소스 검색

Lab completed with proper formatting for time vs times.

PeterMcCormick 6 년 전
부모
커밋
0ef8762a00
1개의 변경된 파일7개의 추가작업 그리고 10개의 파일을 삭제
  1. 7
    10
      src/main/java/io/zipcoder/Main.java

+ 7
- 10
src/main/java/io/zipcoder/Main.java 파일 보기

@@ -45,27 +45,23 @@ public class Main {
45 45
         StringBuilder sb = new StringBuilder();
46 46
         for (String item : groceryAccountedFor) {
47 47
             int timesSeen = hurtLocker.namePrice.get(item).size();
48
-            sb.append(String.format("name:%8s     seen:%2d %s \n", item, timesSeen, timeOrTimes(timesSeen)));
49
-
50
-            //sb.append(String.format("      seen:%3d %s \n", timesSeen, timeOrTimes(timesSeen)));
51
-            sb.append(String.format("=============     =============\n"));
48
+            sb.append(String.format("name:%8s        seen:%2d %s \n", item, timesSeen, timeOrTimes(timesSeen)));
49
+            sb.append(String.format("=============        =============\n"));
52 50
             sb.append(countOccurrences(item));
51
+            sb.append("\n");
53 52
         }
54 53
         int errorCount = hurtLocker.getExceptionsThrown();
55
-        sb.append(String.format("Errors            seen:%2d %s\n", errorCount, timeOrTimes(errorCount)));
54
+        sb.append(String.format("Errors               seen:%2d %s\n", errorCount, timeOrTimes(errorCount)));
56 55
         return sb.toString();
57 56
     }
58 57
     public String countOccurrences(String item) {
59 58
         StringBuilder sb = new StringBuilder();
60 59
         HashMap<Double, Integer> priceOccurrence = hurtLocker.getPriceOccurrence(item);
61 60
         Iterator<Double> itemPriceIterator = priceOccurrence.keySet().iterator();
62
-        int count = 0;
63 61
         while (itemPriceIterator.hasNext()) {
64
-            count++;
65 62
             Double price = itemPriceIterator.next();
66
-            sb.append(String.format("Price:%7.2f     seen:%2d %s\n", price, priceOccurrence.get(price), timeOrTimes(priceOccurrence.get(price))));
67
-            if (count < 2) sb.append(String.format("-------------     -------------\n"));
68
-            sb.append("\n");
63
+            sb.append(String.format("Price:%7.2f        seen:%2d %s\n", price, priceOccurrence.get(price), timeOrTimes(priceOccurrence.get(price))));
64
+            if (itemPriceIterator.hasNext()) sb.append(String.format("-------------        -------------\n"));
69 65
         }
70 66
         return sb.toString();
71 67
     }
@@ -83,6 +79,7 @@ public class Main {
83 79
         System.out.println(output);
84 80
 
85 81
 
82
+
86 83
         // TODO: parse the data in output into items, and display to console.
87 84
 
88 85
     }