Browse Source

Added helpful stuff for the assignment.

Zach Marcin 7 years ago
parent
commit
4b8943f538

+ 2
- 1
.gitignore View File

1
 .idea/*
1
 .idea/*
2
-*.iml
2
+*.iml
3
+target/

+ 9
- 0
README.md View File

11
 
11
 
12
 ## WC
12
 ## WC
13
 Write a program that counts all of the words in a file and prints out all of the words and their counts in descending order.
13
 Write a program that counts all of the words in a file and prints out all of the words and their counts in descending order.
14
+
15
+You can put an text file in resources and get that string's filename from
16
+
17
+`WC.class.getResource("/filename").getFile()`
18
+
19
+I would suggest grabbing a book from `gutenberg.org` and use that as a testing set.
20
+
21
+Also, there is a String iterator constructor so that you can also write some tests using some data built within the tests.
22
+

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

2
 
2
 
3
 import java.io.FileNotFoundException;
3
 import java.io.FileNotFoundException;
4
 import java.io.FileReader;
4
 import java.io.FileReader;
5
+import java.util.Iterator;
5
 import java.util.Scanner;
6
 import java.util.Scanner;
6
 
7
 
7
 public class WC {
8
 public class WC {
8
-    private Scanner sc;
9
+    private Iterator<String> si;
9
 
10
 
10
     public WC(String fileName) {
11
     public WC(String fileName) {
11
         try {
12
         try {
12
-            sc = new Scanner(new FileReader(fileName));
13
+            this.si = new Scanner(new FileReader(fileName));
13
         } catch (FileNotFoundException e) {
14
         } catch (FileNotFoundException e) {
14
             System.out.println(fileName + " Does Not Exist");
15
             System.out.println(fileName + " Does Not Exist");
15
             System.exit(-1);
16
             System.exit(-1);
16
         }
17
         }
17
     }
18
     }
19
+
20
+    public WC(Iterator<String> si) {
21
+        this.si = si;
22
+    }
18
 }
23
 }

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


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

3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
 import org.junit.Test;
4
 import org.junit.Test;
5
 
5
 
6
+import java.util.ArrayList;
7
+import java.util.Arrays;
8
+
6
 public class WCTest {
9
 public class WCTest {
7
 
10
 
8
 }
11
 }