|
@@ -64,31 +64,35 @@ public class Items extends ArrayList<Item>{
|
64
|
64
|
|
65
|
65
|
public static String prettyOutput(Items milk, HashMap<Double, Integer> milkPrices, Items bread, HashMap<Double, Integer> breadPrices, Items cookies, HashMap<Double, Integer> cookiesPrices, Items apples, HashMap<Double, Integer> applesPrices) {
|
66
|
66
|
|
67
|
|
- String result = "name: " + "Milk " + "seen: " + milk.size() + " times\n" +
|
68
|
|
- "====================\n";
|
69
|
|
- for(Double priceM : milkPrices.keySet()) {
|
70
|
|
- result += "Price: " + priceM + " seen: " + milkPrices.get(priceM) + " times\n" +
|
71
|
|
- "---------------------\n";
|
|
67
|
+ String result = String.format("%-8s %4s %12s %d %6s", "name:", "Milk", "seen:", milk.size(), "times\n") +
|
|
68
|
+ String.format("%12s %6s %13s", "=============", "", "=============\n");
|
|
69
|
+ for(Double priceM : milkPrices.keySet()) {
|
|
70
|
+ result += String.format("%-8s %.2f %12s %d %6s", "Price:", priceM, "seen:", milkPrices.get(priceM), "times\n") +
|
|
71
|
+ String.format("%12s %6s %13s", "-------------", "", "-------------\n");
|
72
|
72
|
}
|
73
|
|
- result += "\nname: " + "Bread " + "seen: " + bread.size() + " times\n" +
|
74
|
|
- "====================\n";
|
|
73
|
+
|
|
74
|
+ result += String.format("%-8s %4s %12s %d %6s", "\nname:", "Bread", "seen:", bread.size(), "times\n") +
|
|
75
|
+ String.format("%12s %6s %13s", "=============", "", "=============\n");
|
75
|
76
|
for(Double priceB : breadPrices.keySet()) {
|
76
|
|
- result += "Price: " + priceB + " seen: " + breadPrices.get(priceB) + " times\n" +
|
77
|
|
- "---------------------\n";
|
|
77
|
+ result += String.format("%-8s %.2f %12s %d %6s", "Price:", priceB, "seen:", breadPrices.get(priceB), "times\n") +
|
|
78
|
+ String.format("%12s %6s %13s", "-------------", "", "-------------\n");
|
78
|
79
|
}
|
79
|
|
- result += "\nname: " + "Cookies " + "seen: " + cookies.size() + " times\n" +
|
80
|
|
- "====================\n";
|
|
80
|
+
|
|
81
|
+ result += String.format("%-5s %4s %12s %d %6s", "\nname:", "Cookies", "seen:", cookies.size(), "times\n") +
|
|
82
|
+ String.format("%12s %6s %13s", "=============", "", "=============\n");
|
81
|
83
|
for(Double priceC : cookiesPrices.keySet()) {
|
82
|
|
- result += "Price: " + priceC + " seen: " + cookiesPrices.get(priceC) + " times\n" +
|
83
|
|
- "---------------------\n";
|
|
84
|
+ result += String.format("%-8s %.2f %12s %d %6s", "Price:", priceC, "seen:", cookiesPrices.get(priceC), "times\n") +
|
|
85
|
+ String.format("%12s %6s %13s", "-------------", "", "-------------\n");
|
84
|
86
|
}
|
85
|
|
- result += "\nname: " + "Apples " + "seen: " + apples.size() + " times\n" +
|
86
|
|
- "====================\n";
|
|
87
|
+
|
|
88
|
+ result += String.format("%-7s %4s %12s %d %6s", "\nname:", "Apples", "seen:", apples.size(), "times\n") +
|
|
89
|
+ String.format("%12s %6s %13s", "=============", "", "=============\n");
|
87
|
90
|
for(Double priceA : applesPrices.keySet()) {
|
88
|
|
- result += "Price: " + priceA + " seen: " + applesPrices.get(priceA) + " times\n" +
|
89
|
|
- "---------------------\n";
|
|
91
|
+ result += String.format("%-8s %.2f %12s %d %6s", "Price:", priceA, "seen:", applesPrices.get(priceA), "times\n") +
|
|
92
|
+ String.format("%12s %6s %13s", "-------------", "", "-------------\n");
|
90
|
93
|
}
|
91
|
|
- result += "\nErrors seen: " + ItemParseException.getCount() + " times";
|
|
94
|
+
|
|
95
|
+ result += String.format("%-12s %14s %d %5s", "\nErrors", "seen:", ItemParseException.getCount(), "times");
|
92
|
96
|
|
93
|
97
|
return result;
|
94
|
98
|
|