Bladeren bron

there's a lot of hashmaps here

Trinh Tong 6 jaren geleden
bovenliggende
commit
915d03971d

+ 1
- 5
src/main/java/io/zipcoder/ItemParser.java Bestand weergeven

@@ -54,7 +54,7 @@ public class ItemParser {
54 54
         return new ArrayList<>(Arrays.asList(inputString.split(stringPattern)));
55 55
     }
56 56
 
57
-    public void printToFile(String fileName, String rawItemData) throws FileNotFoundException, ItemParseException {
57
+    public static void printToFile(String fileName, String rawItemData) throws FileNotFoundException, ItemParseException {
58 58
 
59 59
         OutPutObject opo = new OutPutObject(parseRawDataIntoStringArray(rawItemData));
60 60
         PrintStream file = new PrintStream(new File(fileName));
@@ -63,8 +63,4 @@ public class ItemParser {
63 63
         System.setOut(file);
64 64
         System.out.println(opo.outputString());
65 65
     }
66
-
67
-
68
-
69
-
70 66
 }

+ 1
- 1
src/main/java/io/zipcoder/Main.java Bestand weergeven

@@ -14,6 +14,6 @@ public class Main {
14 14
     public static void main(String[] args) throws Exception{
15 15
         String output = (new Main()).readRawDataToString();
16 16
         System.out.println(output);
17
-        // TODO: parse the data in output into items, and display to console.
17
+        ItemParser.printToFile("tariqsShoppingList.txt", output);
18 18
     }
19 19
 }

+ 6
- 3
src/main/java/io/zipcoder/OutPutObject.java Bestand weergeven

@@ -56,10 +56,13 @@ public class OutPutObject {
56 56
                 temp.getPrices().addNewPrice(i.getPrice());
57 57
                 itemCounters.put(i.getName(), temp);
58 58
             } else {
59
-
60 59
                 temp = itemCounters.get(i.getName());
61
-                temp.getPrices().addNewPrice(i.getPrice());
62
-                temp.setCount(temp.getCount()+1);
60
+                if (!temp.getPrices().getPrices().keySet().contains(i.getPrice())) {
61
+                    temp.getPrices().addNewPrice(i.getPrice());
62
+                } else {
63
+                    temp.getPrices().IncrementPriceCounter(i.getPrice());
64
+                }
65
+                temp.setCount(temp.getCount() + 1);
63 66
                 itemCounters.put(i.getName(),temp);
64 67
             }
65 68
         }

+ 2
- 0
src/main/java/io/zipcoder/Prices.java Bestand weergeven

@@ -21,4 +21,6 @@ public class Prices {
21 21
     public HashMap<Double, Integer> getPrices() {
22 22
         return prices;
23 23
     }
24
+
25
+
24 26
 }