Bladeren bron

there's a lot of hashmaps here

Trinh Tong 5 jaren geleden
bovenliggende
commit
915d03971d

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

54
         return new ArrayList<>(Arrays.asList(inputString.split(stringPattern)));
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
         OutPutObject opo = new OutPutObject(parseRawDataIntoStringArray(rawItemData));
59
         OutPutObject opo = new OutPutObject(parseRawDataIntoStringArray(rawItemData));
60
         PrintStream file = new PrintStream(new File(fileName));
60
         PrintStream file = new PrintStream(new File(fileName));
63
         System.setOut(file);
63
         System.setOut(file);
64
         System.out.println(opo.outputString());
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
     public static void main(String[] args) throws Exception{
14
     public static void main(String[] args) throws Exception{
15
         String output = (new Main()).readRawDataToString();
15
         String output = (new Main()).readRawDataToString();
16
         System.out.println(output);
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
                 temp.getPrices().addNewPrice(i.getPrice());
56
                 temp.getPrices().addNewPrice(i.getPrice());
57
                 itemCounters.put(i.getName(), temp);
57
                 itemCounters.put(i.getName(), temp);
58
             } else {
58
             } else {
59
-
60
                 temp = itemCounters.get(i.getName());
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
                 itemCounters.put(i.getName(),temp);
66
                 itemCounters.put(i.getName(),temp);
64
             }
67
             }
65
         }
68
         }

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

21
     public HashMap<Double, Integer> getPrices() {
21
     public HashMap<Double, Integer> getPrices() {
22
         return prices;
22
         return prices;
23
     }
23
     }
24
+
25
+
24
 }
26
 }