ソースを参照

Finally FINISHED

Keith Brinker 6 年 前
コミット
d4b84b6887
共有4 個のファイルを変更した122 個の追加14 個の削除を含む
  1. 12
    0
      pom.xml
  2. 89
    1
      src/main/java/io/zipcoder/ItemParser.java
  3. 20
    7
      src/main/java/io/zipcoder/Main.java
  4. 1
    6
      src/test/java/io/zipcoder/ItemParserTest.java

+ 12
- 0
pom.xml ファイルの表示

@@ -7,6 +7,18 @@
7 7
     <groupId>io.zipcoder</groupId>
8 8
     <artifactId>PainfullAfternoon</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>1.7</source>
17
+                    <target>1.7</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 89
- 1
src/main/java/io/zipcoder/ItemParser.java ファイルの表示

@@ -107,4 +107,92 @@ public class ItemParser {
107 107
         }
108 108
         return completeList;
109 109
     }
110
-}
110
+
111
+    public String printFinalList() throws Exception {
112
+        completeList = getCompleteList();
113
+        StringBuilder listBuilder = new StringBuilder();
114
+
115
+        for(Map.Entry<String,ArrayList<Item>>groceryItems:completeList.entrySet()){
116
+            listBuilder.append("\nname: ");
117
+            listBuilder.append(String.format("%8s",captitalizeFirstLetter(groceryItems.getKey())));
118
+            listBuilder.append("\t\t\t\tseen: "+getOccurencesOfItems(groceryItems.getValue())+" times\n");
119
+            listBuilder.append("==============="+"\t\t\t\t===============\n");
120
+            String priceReport = generatePriceReport(groceryItems);
121
+            listBuilder.append(priceReport);
122
+            listBuilder.append("---------------"+"\t\t\t\t---------------\n");
123
+        }
124
+
125
+        listBuilder.append("\nErrors\t\t\t\t\t\tseen: "+exceptionCounter+" times\n");
126
+
127
+        return listBuilder.toString();
128
+    }
129
+
130
+    public int getOccurencesOfItems(ArrayList list) {
131
+        return list.size();
132
+    }
133
+
134
+    public int getOccurencesOfPrices(ArrayList<Item> list, Double price) {
135
+        int priceCounter = 0;
136
+        for (int i = 0; i < list.size(); i++) {
137
+            if (list.get(i).getPrice().equals(price) ) {
138
+                priceCounter++;
139
+            }
140
+        }
141
+        return priceCounter;
142
+    }
143
+
144
+    public String generatePriceReport(Map.Entry<String, ArrayList<Item>> input) {
145
+        String priceReport = "";
146
+        ArrayList<Double> nonDupPrices = getUniquePrices(input);
147
+        for(int i=0;i<nonDupPrices.size();i++){
148
+            priceReport+="Price";
149
+            priceReport+=(String.format("%10s",nonDupPrices.get(i)));
150
+            priceReport+=("\t\t\t\tseen: "+ getOccurencesOfPrices(input.getValue(),nonDupPrices.get(i))+
151
+                    " times\n");
152
+        }
153
+        return priceReport;
154
+
155
+    }
156
+
157
+    public ArrayList<Double> getUniquePrices(Map.Entry<String, ArrayList<Item>> input) {
158
+        ArrayList<Double> uniquePrices = new ArrayList<>();
159
+        for (int i=0;i<input.getValue().size();i++) {
160
+            if (!uniquePrices.contains(input.getValue().get(i).getPrice())) {
161
+                uniquePrices.add(input.getValue().get(i).getPrice());
162
+            }
163
+        }
164
+        return uniquePrices;
165
+    }
166
+
167
+    public String captitalizeFirstLetter(String input) {
168
+        return input.substring(0, 1).toUpperCase() + input.substring(1).toLowerCase();
169
+    }
170
+
171
+    }
172
+
173
+
174
+//    public int counts() throws Exception {
175
+//        String input = getCompleteList().toString();
176
+//        String[] inputs = input.split("([\\W\\s+])");
177
+//        Map<String, Integer> listCounter = new HashMap<String, Integer>();
178
+//        for (String searchWord : inputs) {
179
+//            if (listCounter.containsKey(searchWord)) {
180
+//                listCounter.put(searchWord, listCounter.get(searchWord) + 1);
181
+//            } else {
182
+//                listCounter.put(searchWord, 1);
183
+//            }
184
+//        }
185
+//        return listCounter.get();
186
+//    }
187
+//    public String printList() throws Exception{
188
+//        ItemParser itemParser = new ItemParser();
189
+//        StringBuilder finalList = new StringBuilder();
190
+//        HashMap<String, ArrayList<Item>> testMap = itemParser.getCompleteList();
191
+//        for (String key : testMap.keySet()) {
192
+//            for (int i = 0; i < testMap.get(key).size(); i++) {
193
+//                finalList.append(("name:      "+ key + " seen:"+testMap.get(key).size()+"\n" + testMap.get(key).get(i).getPrice()));
194
+//            }
195
+//        }
196
+//        return finalList.toString();
197
+//    }
198
+

+ 20
- 7
src/main/java/io/zipcoder/Main.java ファイルの表示

@@ -1,5 +1,6 @@
1 1
 package io.zipcoder;
2 2
 
3
+import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;
3 4
 import org.apache.commons.io.IOUtils;
4 5
 
5 6
 import java.util.*;
@@ -21,15 +22,27 @@ public class Main {
21 22
 
22 23
         System.out.println(output);
23 24
         // TODO: parse the data in output into items, and display to console.
25
+        ItemParser itemParser = new ItemParser();
26
+        Main main = new Main();
24 27
 
28
+        ArrayList<String> itemList = itemParser.parseRawDataIntoStringArray(output);
25 29
 
26
-        ItemParser itemParser = new ItemParser();
27
-        HashMap<String, ArrayList<Item>> testMap = itemParser.getCompleteList();
28
-        for (String key : testMap.keySet()) {
29
-            for (int i = 0; i < testMap.get(key).size(); i++) {
30
-                System.out.println(key + " " + testMap.get(key).get(i).getPrice());
31
-            }
32
-        }
30
+        System.out.println(itemParser.printFinalList());
33 31
         }
32
+
33
+
34 34
     }
35 35
 
36
+//    String s = String.format("%-13s%s", "name:", "bread");
37
+//        System.out.println(s);
38
+//
39
+//                ItemParser itemParser = new ItemParser();
40
+//                HashMap<String, ArrayList<Item>> testMap = itemParser.getCompleteList();
41
+//        for (String key : testMap.keySet()) {
42
+//        for (int i = 0; i < testMap.get(key).size(); i++) {
43
+//        System.out.println("name:    "+key + "                 " + "seen:    " + testMap.get(key).size() + "\n" +
44
+//        "=================              =================\n"
45
+//        +"price:   "+ testMap.get(key).get(i).getPrice() +"                 "+ "seen:    "+ testMap.get(key).size()+"\n"+
46
+//        "----------------              ---------------\n");
47
+//        }
48
+//        }

+ 1
- 6
src/test/java/io/zipcoder/ItemParserTest.java ファイルの表示

@@ -85,11 +85,6 @@ public class ItemParserTest {
85 85
 
86 86
     }
87 87
 
88
-    @Test
89
-    public void parseStringIntoItemTestMultiple() throws ItemParseException{
90
-        Item expected = new Item("milk", 3.23, "food","1/11/2016");
91
-        Item actual = itemParser.parseStringIntoItem(rawMultipleItems);
92
-        assertEquals(expected.toString(), actual.toString());
93
-    }
88
+
94 89
 
95 90
 }