Lauren Green 6 years ago
parent
commit
85b550b316

+ 31
- 2
src/main/java/io/zipcoder/WC.java View File

@@ -2,10 +2,10 @@ package io.zipcoder;
2 2
 
3 3
 import java.io.FileNotFoundException;
4 4
 import java.io.FileReader;
5
-import java.util.Iterator;
6
-import java.util.Scanner;
5
+import java.util.*;
7 6
 
8 7
 public class WC {
8
+    private final List<String> list;
9 9
     private Iterator<String> si;
10 10
 
11 11
     public WC(String fileName) {
@@ -19,5 +19,34 @@ public class WC {
19 19
 
20 20
     public WC(Iterator<String> si) {
21 21
         this.si = si;
22
+
23
+        while(si.hasNext()) {
24
+            list.add(si.next());
25
+        }
26
+    }
27
+
28
+
29
+    public HashMap<String, Integer> countTheWords (String input) {
30
+        input.toLowerCase();
31
+        String[] words = input.split("[\\p{Punct}\\s]+");
32
+        System.out.println(words);
33
+        HashMap<String, Integer> wordCount = new HashMap<String, Integer>();
34
+
35
+        for(String word: words) {
36
+            if(wordCount.get(word) == null) {
37
+                wordCount.put(word, 1);
38
+            } else {
39
+                int value = wordCount.get(word);
40
+                value++;
41
+                wordCount.put(word, value);
42
+            }
43
+        }
44
+
45
+        return wordCount;
46
+    }
47
+
48
+    public Iterator<String> getSi() {
49
+
50
+        return si;
22 51
     }
23 52
 }

+ 7906
- 0
src/main/resources/DoublePlay.txt
File diff suppressed because it is too large
View File


+ 1
- 0
src/main/resources/someTextFile.txt View File

@@ -0,0 +1 @@
1
+Red cow! Yellow cow, blue red cow. Duck!

+ 13
- 0
src/test/java/io/zipcoder/WCTest.java View File

@@ -8,4 +8,17 @@ import java.util.Arrays;
8 8
 
9 9
 public class WCTest {
10 10
 
11
+    @Test
12
+    public void testCountTheWords() {
13
+        //Given
14
+        WC test = new WC(WC.class.getResource("/someTextFile.txt").getFile());
15
+        System.out.println(test.getSi().next());
16
+
17
+
18
+        //When
19
+
20
+        //Then
21
+
22
+    }
23
+
11 24
 }