From 80f6a394fc8a81a2ffb05642dbac0413c21fff34 Mon Sep 17 00:00:00 2001 From: VaziDev Date: Wed, 21 Jul 2021 12:29:55 -0700 Subject: [PATCH 1/7] Upload of Readme.md --- Build.sh | 0 LanguageServer.java | 12 ++++++++++++ Readme.md | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 Build.sh create mode 100644 LanguageServer.java create mode 100644 Readme.md diff --git a/Build.sh b/Build.sh new file mode 100644 index 0000000..e69de29 diff --git a/LanguageServer.java b/LanguageServer.java new file mode 100644 index 0000000..df3dabb --- /dev/null +++ b/LanguageServer.java @@ -0,0 +1,12 @@ +import java.nio.file.Paths; + +public class LanguageServer { + public static void main(String[] args) { + System.out.println("Watching.."); + Paths watchTarget = Paths.get(args[0]).toAbsolutePath().normalize(); + + + } + + } +} \ No newline at end of file diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..a698b01 --- /dev/null +++ b/Readme.md @@ -0,0 +1,20 @@ +#Revature Project Zero +## Budgetar tool +1. Purpose: +Problem: +Solution: + +# Actors / Features: +- A User can: +1. List Items by Necessity +2. Add Items to the Shopping List. + +- An admin can + +- The System can + +- The Application + + +## Quality Requirements +.... From 422454337143493a505abee3cd34578175219578 Mon Sep 17 00:00:00 2001 From: VaziDev Date: Thu, 22 Jul 2021 10:53:47 -0700 Subject: [PATCH 2/7] Intitial Upload of the Budgetar --- Budgetar.java | 40 ++++++++++++++++++++++++++++++++++++++++ Budgetar.md | 10 ++++++++++ 2 files changed, 50 insertions(+) create mode 100644 Budgetar.java create mode 100644 Budgetar.md diff --git a/Budgetar.java b/Budgetar.java new file mode 100644 index 0000000..883abdf --- /dev/null +++ b/Budgetar.java @@ -0,0 +1,40 @@ +//import java.util.*; + +import java.util.HashMap; +import java.util.Scanner; + + + +class Budgetar{ + + public static void main(String[] args) { + int x = 0; //Counter value + HashMap cogs = new HashMap(); //Cost of goods table {Item, Cost} + HashMap cv = new HashMap(); // Stores table {Item, Critial Value} + Scanner item = new Scanner(System.in); // Java Data Input + + System.out.println("Enter Total $ Funds Available:"); + Double tfa = item.nextDouble(); + System.out.println("My Budget: $" + tfa); + + System.out.println(" Please populate the Items List"); + String ItemX; + do { + //ItemX = item.next(); + //Double cogX = item.nextDouble(); //Cost of Goods + + cogs.put(item.next(), item.nextDouble()); + //cogs.put(ItemX, cogX); //Update Cost of Goods Hashmap, Key items + System.out.println(cogs); + x++; + /* if (ItemX.isBlank() || ItemX.isEmpty() || ItemX.toLowerCase().contains("Exit")) { //will detect an Empty 0r Zero values, + x = 0; + } */ + } while (!(item.next().isBlank() || item.next().isEmpty()) || (x<=5) || ItemX.contains("Exit")); + System.out.println(cogs); + } + + +} + + diff --git a/Budgetar.md b/Budgetar.md new file mode 100644 index 0000000..9da3f1c --- /dev/null +++ b/Budgetar.md @@ -0,0 +1,10 @@ +##Project : Revature P0 +##Name: Budgetar Application +##Purpose +1. Budgeting Application +- Start with a set Budget amount, +- Create a list of items that they would like to purchase. +- Index the list of Items, by a Necessity Index value rated from 1-5. +- Local Persistence (File, .txt) or local SQL +- Calculate/ Create Shopping List Recommendation based on the data on hand. +- \ No newline at end of file From 9c5f11abac7d1d9e502dcfb7d8160c54e46f6702 Mon Sep 17 00:00:00 2001 From: VaziDev Date: Thu, 22 Jul 2021 12:37:35 -0700 Subject: [PATCH 3/7] Intitial upload of Budgetar.java --- Budgetar.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Budgetar.java b/Budgetar.java index 883abdf..a6125e8 100644 --- a/Budgetar.java +++ b/Budgetar.java @@ -1,5 +1,6 @@ -//import java.util.*; +//package P0;// +import java.util.*; import java.util.HashMap; import java.util.Scanner; @@ -20,17 +21,12 @@ public static void main(String[] args) { System.out.println(" Please populate the Items List"); String ItemX; do { - //ItemX = item.next(); - //Double cogX = item.nextDouble(); //Cost of Goods cogs.put(item.next(), item.nextDouble()); //cogs.put(ItemX, cogX); //Update Cost of Goods Hashmap, Key items System.out.println(cogs); x++; - /* if (ItemX.isBlank() || ItemX.isEmpty() || ItemX.toLowerCase().contains("Exit")) { //will detect an Empty 0r Zero values, - x = 0; - } */ - } while (!(item.next().isBlank() || item.next().isEmpty()) || (x<=5) || ItemX.contains("Exit")); + } while (!(item.equals(null) )); //|| item.next().isEmpty()) || (x<=5) || ItemX.contains("Exit")); System.out.println(cogs); } From 30b6de812cef45dcda68ecbb5392da47e3b69244 Mon Sep 17 00:00:00 2001 From: Leonard N Date: Mon, 26 Jul 2021 09:35:01 -0700 Subject: [PATCH 4/7] Initial Load of IntelliJ Files Created new file to work within the intelliJ/maven program --- Budgetar.java | 67 ++++++++++++++++++++++------------------------- BudgetarFile.java | 66 ++++++++++++++++++++++++++++++++++++++++++++++ getData.java | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 36 deletions(-) create mode 100644 BudgetarFile.java create mode 100644 getData.java diff --git a/Budgetar.java b/Budgetar.java index a6125e8..9595a1d 100644 --- a/Budgetar.java +++ b/Budgetar.java @@ -1,36 +1,31 @@ -//package P0;// - -import java.util.*; -import java.util.HashMap; -import java.util.Scanner; - - - -class Budgetar{ - - public static void main(String[] args) { - int x = 0; //Counter value - HashMap cogs = new HashMap(); //Cost of goods table {Item, Cost} - HashMap cv = new HashMap(); // Stores table {Item, Critial Value} - Scanner item = new Scanner(System.in); // Java Data Input - - System.out.println("Enter Total $ Funds Available:"); - Double tfa = item.nextDouble(); - System.out.println("My Budget: $" + tfa); - - System.out.println(" Please populate the Items List"); - String ItemX; - do { - - cogs.put(item.next(), item.nextDouble()); - //cogs.put(ItemX, cogX); //Update Cost of Goods Hashmap, Key items - System.out.println(cogs); - x++; - } while (!(item.equals(null) )); //|| item.next().isEmpty()) || (x<=5) || ItemX.contains("Exit")); - System.out.println(cogs); - } - - -} - - +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.HashMap; +import java.util.Scanner; + + +public class Budgetar { + + + + public static void main(String[] args) { + String a = new BudgetarFile().CreateDataFile("cogsFile.csv"); //Make sure the Data Storazge File Exists/Create + double b = new getData().GetBudget(0); // Get the Budget Amount + HashMap c = new getData().GetShoppingList(); // Collect the Items Cost Data + //Boolean d = new BudgetarFile().WriteToDataFile(Boolean.TRUE); + String[] e = new getData().IndexShoppingList(); //Edit the Items Necessity Index + + //String b = new BudgetarFile().CreateDataFile("TestFile.csv"); + //String c = new BudgetarFile().ReadDataFile("TestFile.csv"); + //System.out.print("Budget Amount:" + c); + + + //GetShoppingList(); + //IndexShoppingList(); + // CreateShoppingListFile(); + } + +} + + diff --git a/BudgetarFile.java b/BudgetarFile.java new file mode 100644 index 0000000..3b75c01 --- /dev/null +++ b/BudgetarFile.java @@ -0,0 +1,66 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.io.FileWriter; +import java.util.stream.Collectors; +import java.util.stream.Stream; +//import org.supercsv.io.*; + + +public class BudgetarFile extends getData{ + + File cogFile = new File("FileCogs.csv"); + String fileName; + + static {}; + + String CreateDataFile(String fileName){ + try { + if (!(cogFile.exists())) { + cogFile.createNewFile(); + fileName = cogFile.getName(); + System.out.println(" New File Created: " + fileName); + } + else if(cogFile.exists()) System.out.println("File: " + fileName + " Already Exists"); + }catch (FileNotFoundException e){ + System.out.println("File Not Found Error"); + }catch ( IOException e){ + System.out.println(" Error encountered creating new File"); + }finally { + System.out.println("Will output the current values to File"); + } + return fileName; + + } + /** + Boolean WriteToDataFile( Boolean aTrue, String filepath){ + StringWriter dataWriter = new StringWriter(); + HashMap cogZ = new getData().cogs; + System.out.println("Current List: " + cogZ); + + try (ICsvListWriter listWriter = new CsvListWriter(output, CsvPreference.STANDARD_PREFERENCE)){ + filepath = cogFile.getPath(); + ICsvMapWriter csvListWriter = new CsvMapWriter(); + dataWriter.write(String.valueOf(cogZ)); + System.out.println(cogZ.size() + " Items of Data Successfully Written"); + }catch (Exception e){ + System.out.println( "Error: Unable to Write to File"); + } + return Boolean.TRUE; + } + + + HashMap GetDataFromFile(final String filepath){ ///Stack Overflow sample + String filePath = cogFile.getName(); + Stream lines = Files.lines(Paths.get(filePath)); + HashMap dataZ = lines.map(line -> line.split(",")).collect(Collectors.toMap(line -> line[0], line -> line [1])); + lines.close(); + // + + } + **/ +} \ No newline at end of file diff --git a/getData.java b/getData.java new file mode 100644 index 0000000..8aebf61 --- /dev/null +++ b/getData.java @@ -0,0 +1,62 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.HashMap; +import java.util.Scanner; + +public class getData { + + Scanner entry = new Scanner(System.in); + HashMap cogs = new HashMap(); + HashMap nv = new HashMap(); + int x = 0; + double tfa = 100.00; // start value to prove action performed + + + double GetBudget(double tfa) { //get the Total Budget Size + Scanner entry = new Scanner(System.in); + System.out.println(" Enter Total fund Available: $"); + tfa = entry.nextDouble(); + System.out.println("My Budget: $" + tfa); + return tfa; + } + + HashMap GetShoppingList() { + Scanner entry = new Scanner(System.in); + HashMap cogs = new HashMap(); + int x = 0; + System.out.println("Create a Shopping List"); + do { + String[] itemX = entry.nextLine().split("\\s+"); + //double costX = entry.nextDouble(); + x++; + try { + if (itemX.equals("")) { //if the scanner entry is NOT empty, continue, else catch exception + break; + } else { + cogs.put(itemX[0], itemX[1]); //, costX); + } + } catch (Exception e) { + System.out.println(" Shopping List" + cogs); + break; + } finally { + System.out.println(cogs); + } + } while (cogs.size() < 5 || entry.nextLine().equals("")); //Limits the item list to 10 Items + // Items + System.out.println("Shopping List: " + cogs); + //String itemXlist[] = cogs.keySet(); + return cogs; + } + + + String[] IndexShoppingList() { + String[] itemZ = cogs.keySet().toArray(new String[0]); + HashMap nv = new HashMap(); + System.out.println("Shopping List Items : " + itemZ); + return itemZ; + } + +} + + From 1f0f1d3b9f58309ee1c9fa676f11a0c82b7e4444 Mon Sep 17 00:00:00 2001 From: Leonard N Date: Thu, 5 Aug 2021 07:33:48 -0700 Subject: [PATCH 5/7] Adde files vi aupload -post presentation --- Budgetar.java | 77 ++++++++++++----- BudgetarFile.java | 107 +++++++++++------------- BudgetarTest.java | 8 ++ GetData.java | 206 ++++++++++++++++++++++++++++++++++++++++++++++ GetDataTest.java | 43 ++++++++++ Item.java | 9 ++ ItemTest.java | 6 ++ NettyServer.java | 61 ++++++++++++++ OptionList.java | 43 ++++++++++ Server.java | 23 ++++++ ShoppingList.java | 43 ++++++++++ cogsFile.csv | 25 ++++++ 12 files changed, 570 insertions(+), 81 deletions(-) create mode 100644 BudgetarTest.java create mode 100644 GetData.java create mode 100644 GetDataTest.java create mode 100644 Item.java create mode 100644 ItemTest.java create mode 100644 NettyServer.java create mode 100644 OptionList.java create mode 100644 Server.java create mode 100644 ShoppingList.java create mode 100644 cogsFile.csv diff --git a/Budgetar.java b/Budgetar.java index 9595a1d..34b0d53 100644 --- a/Budgetar.java +++ b/Budgetar.java @@ -1,31 +1,68 @@ +package projectzero.budgetar; + import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.HashMap; +import java.nio.file.Path; import java.util.Scanner; +import java.util.logging.Logger; public class Budgetar { - - - public static void main(String[] args) { - String a = new BudgetarFile().CreateDataFile("cogsFile.csv"); //Make sure the Data Storazge File Exists/Create - double b = new getData().GetBudget(0); // Get the Budget Amount - HashMap c = new getData().GetShoppingList(); // Collect the Items Cost Data - //Boolean d = new BudgetarFile().WriteToDataFile(Boolean.TRUE); - String[] e = new getData().IndexShoppingList(); //Edit the Items Necessity Index + Logger LOG = Logger.getAnonymousLogger(); + LOG.info("Starting Application..."); + LOG.info("Initiating server...."); + File filename = new File("cogsFile.csv"); + new Server().initialize(8080); + Path filepath = filename.toPath(); + GetData a = new GetData(); + a.myFile(); //check/create file. + a.FileContent(); + Scanner entry = new Scanner(System.in); + Double tfa=0.00; + a.calcBalance(); - //String b = new BudgetarFile().CreateDataFile("TestFile.csv"); - //String c = new BudgetarFile().ReadDataFile("TestFile.csv"); - //System.out.print("Budget Amount:" + c); + int x; + String option = ""; + do { + System.out.println("\nCurrent Budget:$" + a.tfa); + System.out.println("Total Est Cost: $" + a.sumCost); + System.out.println("Account Balance: $" + (a.tfa - a.sumCost)); + System.out.println("\nSelect an Option"); //working + System.out.println("1:View List | 2:New List | 3:Edit Budget| 4:Edit Ratings | 0:Exit"); - //GetShoppingList(); - //IndexShoppingList(); - // CreateShoppingListFile(); - } - -} + x = entry.nextInt(); + switch (x) { + case 1: + option = "Current list"; + System.out.println("Retrieving Shopping List....."); + a.FileContent().displayData(); + break; + case 2: + option = "New List"; + a.ShoppingList(); + a.toFile(); + break; + case 3: + option = "Edit Budget"; + a.GetBudget(); + break; + case 4: + option = "Index Items"; + System.out.println(" Retrieving Items List..."); + a.IndexList(); + break; + case 0: + option = "Exit"; + System.out.println("Exiting... Good Bye!"); + return; + default: + option = "Invalid Entry"; + System.out.println("Invalid Selection.."); + break; + } + } while (true); + } +} diff --git a/BudgetarFile.java b/BudgetarFile.java index 3b75c01..8b6e1db 100644 --- a/BudgetarFile.java +++ b/BudgetarFile.java @@ -1,66 +1,51 @@ -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.StringWriter; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashMap; -import java.io.FileWriter; -import java.util.stream.Collectors; -import java.util.stream.Stream; -//import org.supercsv.io.*; - - -public class BudgetarFile extends getData{ - - File cogFile = new File("FileCogs.csv"); - String fileName; - - static {}; +package projectzero.budgetar; - String CreateDataFile(String fileName){ - try { - if (!(cogFile.exists())) { - cogFile.createNewFile(); - fileName = cogFile.getName(); - System.out.println(" New File Created: " + fileName); - } - else if(cogFile.exists()) System.out.println("File: " + fileName + " Already Exists"); - }catch (FileNotFoundException e){ - System.out.println("File Not Found Error"); - }catch ( IOException e){ - System.out.println(" Error encountered creating new File"); - }finally { - System.out.println("Will output the current values to File"); - } - return fileName; +import java.io.*; +import java.util.HashMap; +public class BudgetarFile extends GetData { + File cogFile = new File("FileCogs.csv"); + String filepath; + + + String CreateDataFile(String filepath){ + try { + if (!(cogFile.exists())) { + cogFile.createNewFile(); + filepath = cogFile.getName(); + System.out.println(" New File Created: " + filepath); + } + else if(cogFile.exists()) System.out.println("File: " + filepath + " Already Exists"); + }catch (FileNotFoundException e){ + System.out.println("File Not Found Error"); + }catch ( IOException e){ + System.out.println(" Error encountered creating new File"); + }finally { + System.out.println("Will output the current values to File"); } - /** - Boolean WriteToDataFile( Boolean aTrue, String filepath){ - StringWriter dataWriter = new StringWriter(); - HashMap cogZ = new getData().cogs; - System.out.println("Current List: " + cogZ); - - try (ICsvListWriter listWriter = new CsvListWriter(output, CsvPreference.STANDARD_PREFERENCE)){ - filepath = cogFile.getPath(); - ICsvMapWriter csvListWriter = new CsvMapWriter(); - dataWriter.write(String.valueOf(cogZ)); - System.out.println(cogZ.size() + " Items of Data Successfully Written"); - }catch (Exception e){ - System.out.println( "Error: Unable to Write to File"); - } - return Boolean.TRUE; + return filepath; + } + + + String[] ReadDataFile(String filepath){ + String xFile=filepath; + String line; + int x = 0; + System.out.println("Retrieving Shopping List:"); + try{ + BufferedReader brRead = new BufferedReader(new FileReader(cogFile)); + while ((line = brRead.readLine()) != null) { + System.out.println(x + ". " + line); + dataList = line.split(","); //Stores a list of Items to String Array. + //System.out.println(x + ". Item: " + dataList[0]); + x++; + } + }catch (FileNotFoundException e){ + e.printStackTrace(); + }catch (IOException e){ + e.printStackTrace(); } + return dataList; + } - - HashMap GetDataFromFile(final String filepath){ ///Stack Overflow sample - String filePath = cogFile.getName(); - Stream lines = Files.lines(Paths.get(filePath)); - HashMap dataZ = lines.map(line -> line.split(",")).collect(Collectors.toMap(line -> line[0], line -> line [1])); - lines.close(); - // - - } - **/ -} \ No newline at end of file +} diff --git a/BudgetarTest.java b/BudgetarTest.java new file mode 100644 index 0000000..4d22251 --- /dev/null +++ b/BudgetarTest.java @@ -0,0 +1,8 @@ +package projectzero.budgetar; + +import static org.junit.jupiter.api.Assertions.*; + +class BudgetarTest { + + +} \ No newline at end of file diff --git a/GetData.java b/GetData.java new file mode 100644 index 0000000..b84b801 --- /dev/null +++ b/GetData.java @@ -0,0 +1,206 @@ +package projectzero.budgetar; + +import io.javalin.Javalin; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; +import java.util.stream.Stream; +import io.javalin.Javalin; +//import io.netty.buffer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + + +public class GetData { + //public ArrayList httpList; + File filename = new File("cogsFile.csv"); + Path filepath = filename.toPath(); + Scanner entry = new Scanner(System.in); + HashMap cogs = new HashMap>(); + int x = 0; + double tfa = 0.00; // Total Funds Available + double sumCost=0.00; //Total Cost of Goods + double cashBalance =0.00; + String[] dataList = new String[0]; + ArrayList itemList= new ArrayList<>(); //contains a list of all Items osn shopping List. + ArrayList httpList= new ArrayList<>(); //contains a list of all Items osn shopping List. + + //update the budget value + public void GetBudget() { //get the Total Budget Size + System.out.println(" Enter Total funds Available: $"); + this.tfa = entry.nextDouble(); + System.out.println(" TFA Wallet Updated:... $" + this.tfa ); + return this; + } + + //Crete anew Shopping list and discard the old one. + public void ShoppingList() { + StringBuilder sbWrite = new StringBuilder(); + int x = 0; + System.out.println("Create a Shopping List"); + ArrayList itemList = this.itemList; + do { + String[] itemX = entry.nextLine().split("\\s+"); + try { + if (!(itemX.equals(""))) { //if the scanner entry is NOT empty, continue, else catch exception + cogs.put(itemX[0], itemX[1]); // costX); //Store the data in a hashmap + } + x++; + } catch (Exception e) { + break; + } + } while (cogs.size() < 5 || entry.nextLine().equals("")); //Limits the item list to 10 ItemsSystem.out.println(br); + MapToArray(); //Convert Hashmap to Array List + System.out.println("Rate by Necessity Index (i.e Must have): 1-5 : "); + nvIndex(); //index the items + return this; + } + + //will edit the items in the File. + public void IndexList() { + String line; + String tempList=""; + System.out.println("Rate by Necessity Index (Must have): 1-5 : "); + try { + BufferedReader brRead = new BufferedReader(new FileReader(this.filename)); //opens up the read from File Function + while ((line = brRead.readLine()) != null) { + System.out.println(line.split(",")[0]); + int nvIndex = entry.nextInt(); + itemList.add(line.split(",")[0] + "," + line.split(",")[1] + "," + nvIndex); + x++; + } + + }catch (FileNotFoundException e){ + e.printStackTrace(); + }catch (IOException e){ + + e.printStackTrace(); + } + //System.out.println(itemList); + System.out.println("Update Values? Y/N"); + String y = entry.nextLine(); + if (y.toUpperCase(Locale.ROOT).equals("Y")) { + toFile(); + }else { + System.out.println("Discarding New List...."); + } + return this; + } + + //Edits the Items on the itemList Array + public void nvIndex(){ + for (int x=itemList.size()-1; x >= 0; x--) { + System.out.println(itemList.get(x)); + itemList.add( itemList.get(x) + "," + entry.nextInt()); + } + } + + //Verifies True if file Exists, or will create a new file + public void myFile(){ + filename = this.filename; + try { + if (!(filename.exists())) { + filename.createNewFile(); + //filepath = filepath.getName(); + System.out.println(" Error:... " + filename); + } + else if(filename.exists()) System.out.println("Success: " + filename); + }catch (FileNotFoundException e){ + System.out.println("File Not Found Error:..." + filename); + }catch ( IOException e){ + System.out.println(" Error encountered creating new File:...." + filename); + }finally { + System.out.println(""); + } + return this; + } + + //Writes Data to File + public GetData toFile() { + System.out.println("Save current List ?: (Y/N)"); + final String y = entry.nextLine().toString(); + String line =""; + HashMap data = this.cogs; + int x = 0; + try { + System.out.println("Writing to File"); + BufferedWriter brWrite = new BufferedWriter(new FileWriter(filename)); //Opens up the Write to File function + for (String t : itemList) { + brWrite.write(t + "\n"); //Write the String to the File + x++; + } + brWrite.close(); //close the File after writing **/ + } catch (FileNotFoundException e) { + //Error message out + } catch (IOException e) { + //Error Message out: use logger + } + return this; + } + + //display the content of the .csv file + public GetData FileContent(){ + //Iterator iter = itemList.iterator(); + try(Stream lines = Files.lines(this.filepath)){ + lines.forEach(s -> itemList.add(s)); + }catch (IOException e){ + System.err.println("Failed to stream File"); + } + return this; + } + + //Data Display Method + public GetData displayData(){ + itemList.forEach(s -> System.out.println((s.split(",")[0] + ", $" + s.split(",")[1]))); + return this; + } + + //calculate trx Balance. + public void calcBalance(){ + try { + sumCost = this.itemList.stream().mapToDouble(s -> Double.parseDouble(s.split(",")[1])).sum(); + }catch (Exception e){ + e.printStackTrace(); + } + //System.out.println("Total Est Cost: $" + sumCost); + //System.out.println("Account Balance: $" + (cashBalance = this.tfa - sumCost)); + } + + //convert hashmap to arrayList + public void MapToArray() { // fucntion will convert current Hashmap to Array List + Iterator iCogs = cogs.entrySet().stream().iterator();; + this.itemList.clear(); + while (iCogs.hasNext()) { + Map.Entry pairs = (Map.Entry)iCogs.next(); + this. itemList.add(pairs.getKey() + "," + pairs.getValue() + ","); + } + this.itemList = itemList; + System.out.println(itemList); + } + + //add to the List + public void addItemToList(){ + System.out.println("Add: (Item,Cost,nvValue)"); + String item = entry.nextLine(); + this.itemList.add(item.split("")[0] + "," + item.split("")[1] + "," + item.split("")[2] + "\n"); + System.out.println("Update File: Y/N"); + if(entry.nextLine().toUpperCase(Locale.ROOT) == "Y"){ + this.toFile(); + } + } + + //Remove from list + public void rmItemFromlist(){ + System.out.println("Select Item to be Deleted"); + String xItem = entry.nextLine(); + this.itemList.remove(xItem); + } + + + + +} + diff --git a/GetDataTest.java b/GetDataTest.java new file mode 100644 index 0000000..74267e2 --- /dev/null +++ b/GetDataTest.java @@ -0,0 +1,43 @@ +package projectzero.budgetar; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.*; + +class GetDataTest { + + //will test the existence of a file + @Test + @DisplayName("Test for the existence of the file") + void myFileExists() { + File fileTest = new GetData().filepath.toFile(); + Assertions.assertTrue(fileTest.exists()); + + } + + @Test + @DisplayName("Test if the file is Read enabled") + void myFileRead(){ + File fileTest = new GetData().filepath.toFile(); + Assertions.assertTrue(fileTest.canRead()); + + } + + @Test + @DisplayName("Test if the File is Write Enabled") + void myFileWrite(){ + File fileTest = new GetData().filepath.toFile(); + Assertions.assertTrue(fileTest.canWrite()); + } + + @Test + @DisplayName("Test if the Budget value is reset") + void myBudget(){ + double amt = new GetData().tfa; + Assertions.assertEquals(0, amt); + } +} \ No newline at end of file diff --git a/Item.java b/Item.java new file mode 100644 index 0000000..b20f71e --- /dev/null +++ b/Item.java @@ -0,0 +1,9 @@ +package projectzero.budgetar; + + +class Item { + String name; + Double price; + int iValue; + +} diff --git a/ItemTest.java b/ItemTest.java new file mode 100644 index 0000000..4e8280a --- /dev/null +++ b/ItemTest.java @@ -0,0 +1,6 @@ +package projectzero.budgetar; + + +class ItemTest { + +} \ No newline at end of file diff --git a/NettyServer.java b/NettyServer.java new file mode 100644 index 0000000..f000d77 --- /dev/null +++ b/NettyServer.java @@ -0,0 +1,61 @@ +package projectzero.budgetar; + +import io.netty.bootstrap.ServerBootstrap; + +import io.netty.channel.*; +import io.netty.channel.nio.NioEventLoopGroup; + import io.netty.channel.socket.SocketChannel; + import io.netty.channel.socket.nio.NioServerSocketChannel; + +import java.awt.*; + +/** + * Discards any incoming data. + */ +public class NettyServer { + + private int port=8080; + + public NettyServer(int port) { + this.port = port; + return; + } + + public void run() throws Exception { + EventLoopGroup bossGroup = new NioEventLoopGroup(); // (1) + EventLoopGroup workerGroup = new NioEventLoopGroup(); + try { + ServerBootstrap b = new ServerBootstrap(); // (2) + b.group(bossGroup, workerGroup) + .channel(NioServerSocketChannel.class) // (3) + .childHandler(new ChannelInitializer() { // (4) + @Override + public void initChannel(SocketChannel ch) throws Exception { + ch.pipeline().addLast(new ChannelInboundHandlerAdapter()); + } + }) + .option(ChannelOption.SO_BACKLOG, 128) // (5) + .childOption(ChannelOption.SO_KEEPALIVE, true); // (6) + + // Bind and start to accept incoming connections. + ChannelFuture f = b.bind(port).sync(); // (7) + + // Wait until the server socket is closed. + // In this example, this does not happen, but you can do that to gracefully + // shut down your server. + f.channel().closeFuture().sync(); + } finally { + workerGroup.shutdownGracefully(); + bossGroup.shutdownGracefully(); + } + } + + public static void main(String[] args) throws Exception { + int port = 8080; + if (args.length > 0) { + port = Integer.parseInt(args[0]); + } + + new NettyServer(port).run(); + } +} \ No newline at end of file diff --git a/OptionList.java b/OptionList.java new file mode 100644 index 0000000..1c4d0f4 --- /dev/null +++ b/OptionList.java @@ -0,0 +1,43 @@ +package projectzero.budgetar; + +import java.util.*; + +public class OptionList { + + + + + + public static void main(String[] args) { + HashMap cogs = new HashMap<>(); + ArrayList itemList = new ArrayList(); + ArrayList itemCost = new ArrayList(); + Scanner entry = new Scanner(System.in); + cogs.put("Bread", 5.25); + cogs.put("Sugar ", 3.25); + cogs.put("Flour", 2.99); + cogs.put("Eggs", 4.50); + cogs.put("Butter", 3.15); + cogs.put("Milk", 4.25); + cogs.put("Vanilla", 1.25); + cogs.put("Coffee", 5.25); + cogs.put("Water", 1.50); + cogs.put("Sausage", 6.99); + + + Iterator iCogs = cogs.entrySet().stream().iterator(); + while (iCogs.hasNext()) { + Map.Entry pairs = (Map.Entry) iCogs.next(); + System.out.println(pairs.getKey() + ": $" + pairs.getValue()); + itemList.add(pairs.getKey() + ":$" + pairs.getValue()); + } + System.out.println(itemList); + + int x=0; + //while(itemList.stream().iterator().hasNext()) + + + System.out.println("Indexed List:" + itemList); + + } +} diff --git a/Server.java b/Server.java new file mode 100644 index 0000000..6f3000d --- /dev/null +++ b/Server.java @@ -0,0 +1,23 @@ +package projectzero.budgetar; + +import io.javalin.Javalin; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.stream.Stream; +import org.slf4j.*; +import org.slf4j.LoggerFactory; + +public class Server { + + public void initialize(int port) { + int x = 0; + ArrayList xlist = new GetData().FileContent().itemList; // .HttpDisplayList().httpList; + Iterator xList = xlist.stream().iterator(); + Javalin app = Javalin.create().start(port); + //ArrayList finalX = x; + app.get("/", ctx -> ctx.result("Success: Connection Initiated :\n" + xlist)); + + } + } + diff --git a/ShoppingList.java b/ShoppingList.java new file mode 100644 index 0000000..a551c20 --- /dev/null +++ b/ShoppingList.java @@ -0,0 +1,43 @@ +package projectzero.budgetar; +/** + import javax.xml.transform.sax.SAXSource; +import java.io.IOException; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.stream.Stream; + +import com.sun.net.httpserver.HttpServer; +import io.javalin.Javalin; +import reactor.netty.disposableServer; +import reactor.netty.tcp.TccpServer; + + +public class ShoppingList extends GetData { + HashMap cogsList = cogs; + HashMap nvList = nv; + + public ShoppingList() { + //Object[] xList = new Object[]; + try (Stream String = Files.lines(streamDictionary)) { + } catch (IOException e) { + + } + } + + //Create Servers, + // Netty Server + public static void server(){ + HttpServer.create().route(8080).route( + route -> route.get(path: "/" (req, res) -> res.sendString (Mono.just("Hello Kanyigis!"))) + .get(path: "/Hello/{param})", + (request, response) -> response.sendString( Mono.just("Hello, " + request.parm)"param")) + ).bindNow().onDispose().block(); + } + + //Javalin Server + public static void javalinServer(){ + Javalin server = Javalin.create().start(8080); + server.get("/hello", context -> context.result("

Hello

Atech24

from Javalin ").contentType("text/html")); + } +} + **/ \ No newline at end of file diff --git a/cogsFile.csv b/cogsFile.csv new file mode 100644 index 0000000..fb332dc --- /dev/null +++ b/cogsFile.csv @@ -0,0 +1,25 @@ +Bread,5.25,4 +Milk,3.19,3 +Eggs,3.99,5 +Coffee,11.99,2 +Sugar,3.99,4 +Flour,5.29,3 +Butter,3.99,2 +Cheese,6.99,5 +Yogurt,6.69,5 +Cereal,3.99,4 +Onions,4.26,2 +Garlic,0.56,4 +Apples,7.25,1 +Bananas,3.2,4 +Salt,3.25,2 +Honey,12.98,1 +Chicken,5.55,4 +Fish,6.75,4 +Tomatoes,3.66,5 +Cellery,1.79,4 +Beer,15.99,5 +Wine,16.39,3 +Mangoes,3.25,5 +Honey,2.15,4 +Paper-Towel,4.45,5 \ No newline at end of file From 484a2c03f189a21241651c5f8c074e0e974b0273 Mon Sep 17 00:00:00 2001 From: Leonard N Date: Thu, 5 Aug 2021 07:46:43 -0700 Subject: [PATCH 6/7] update .md file --- Readme.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index a698b01..a3b74dd 100644 --- a/Readme.md +++ b/Readme.md @@ -1,20 +1,33 @@ #Revature Project Zero ## Budgetar tool 1. Purpose: -Problem: -Solution: + to create a shopping list application that can be Edited, and updated by the user, and issue some form of budgeting functionality i.e Cost Budgeting # Actors / Features: - A User can: 1. List Items by Necessity 2. Add Items to the Shopping List. +3. Edit Item on the elist +4. Create new list +5. Update Total Budget amount +6. -- An admin can - The System can +- 1. Pull Data from a .csv file +- 2. Write Data to a .csv File +- 3. Send Data to a server +- 4. Claculate Budget costs +- 5. Create new list - The Application +- CLI based Interaction +- .CSV File Persistence +- Web server Display ## Quality Requirements -.... +1. Able to Retrieve File Data +2. Able to Write to File +3. Able to update Data +4. Able to Display Data. From ab290b1005033d249c059e13ef74ff6c423c9791 Mon Sep 17 00:00:00 2001 From: Leonard N Date: Thu, 5 Aug 2021 08:12:26 -0700 Subject: [PATCH 7/7] Update Readme.md --- Readme.md | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Readme.md b/Readme.md index a3b74dd..6755bb8 100644 --- a/Readme.md +++ b/Readme.md @@ -4,29 +4,28 @@ to create a shopping list application that can be Edited, and updated by the user, and issue some form of budgeting functionality i.e Cost Budgeting # Actors / Features: -- A User can: +## A User can: 1. List Items by Necessity 2. Add Items to the Shopping List. 3. Edit Item on the elist 4. Create new list 5. Update Total Budget amount -6. -- The System can -- 1. Pull Data from a .csv file -- 2. Write Data to a .csv File -- 3. Send Data to a server -- 4. Claculate Budget costs -- 5. Create new list +# The System can +1. Pull Data from a .csv file +2. Write Data to a .csv File +3. Send Data to a server +4. Claculate Budget costs +5. Create new list -- The Application -- CLI based Interaction -- .CSV File Persistence -- Web server Display +# The Application +1. CLI based Interaction +2. .CSV File Persistence +3. Web server Display -## Quality Requirements +## Functionality Requirements 1. Able to Retrieve File Data 2. Able to Write to File 3. Able to update Data