Procházet zdrojové kódy

finished everything, it works

Luis Romero před 6 roky
rodič
revize
5231662b77

+ 12
- 0
src/main/java/io/zipcoder/ItemParser.java Zobrazit soubor

@@ -171,6 +171,18 @@ public class ItemParser {
171 171
         return sb.toString();
172 172
     }
173 173
 
174
+    public String getReportAsString() {
175
+        StringBuilder sb = new StringBuilder();
176
+        for (String name : itemOrganizer.keySet()) {
177
+            if (! name.equals("EMPTY")) {
178
+                sb.append(itemNameAndCountAsString(name) + "\n");
179
+                sb.append(pricesAndTheirCountAsString(getPricesAndTheirCount(name)) + "\n");
180
+            }
181
+        }
182
+        sb.append(getIpe().errorCountAsString());
183
+        return sb.toString();
184
+    }
185
+
174 186
     public Item parseStringIntoItem(String rawItem) throws ItemParseException {
175 187
 
176 188
         String emptyFieldName = "";

+ 13
- 11
src/main/java/io/zipcoder/Main.java Zobrazit soubor

@@ -21,16 +21,18 @@ public class Main {
21 21
         itemParser.createItems();
22 22
         itemParser.addNameAndItemsOfSameNameToItemOrganizer();
23 23
 
24
-        System.out.println(itemParser.itemNameAndCountAsString("milk"));
25
-        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("milk")));
26
-        System.out.println(itemParser.itemNameAndCountAsString("bread"));
27
-        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("bread")));
28
-        System.out.println(itemParser.itemNameAndCountAsString("cookies"));
29
-        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("cookies")));
30
-        System.out.println(itemParser.itemNameAndCountAsString("apples"));
31
-        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("apples")));
32
-        System.out.println(itemParser.getIpe().errorCountAsString());
33
-
34
-
24
+        // Prints report in alphabetical order by name (the prices/counts match output.txt)
25
+        System.out.println(itemParser.getReportAsString());
26
+
27
+        // These commands (commented out) will print the same information in the order of output.txt
28
+//        System.out.println(itemParser.itemNameAndCountAsString("milk"));
29
+//        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("milk")));
30
+//        System.out.println(itemParser.itemNameAndCountAsString("bread"));
31
+//        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("bread")));
32
+//        System.out.println(itemParser.itemNameAndCountAsString("cookies"));
33
+//        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("cookies")));
34
+//        System.out.println(itemParser.itemNameAndCountAsString("apples"));
35
+//        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("apples")));
36
+//        System.out.println(itemParser.getIpe().errorCountAsString());
35 37
     }
36 38
 }