Преглед на файлове

Added helpful stuff for the assignment.

Zach Marcin преди 7 години
родител
ревизия
4b8943f538
променени са 5 файла, в които са добавени 21 реда и са изтрити 3 реда
  1. 2
    1
      .gitignore
  2. 9
    0
      README.md
  3. 7
    2
      src/main/java/io/zipcoder/WC.java
  4. 0
    0
      src/main/resources/someTextFile.txt
  5. 3
    0
      src/test/java/io/zipcoder/WCTest.java

+ 2
- 1
.gitignore Целия файл

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

+ 9
- 0
README.md Целия файл

@@ -11,3 +11,12 @@ Characters include `()` `{}` `[]` `<>` `""` `''`
11 11
 
12 12
 ## WC
13 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 Целия файл

@@ -2,17 +2,22 @@ package io.zipcoder;
2 2
 
3 3
 import java.io.FileNotFoundException;
4 4
 import java.io.FileReader;
5
+import java.util.Iterator;
5 6
 import java.util.Scanner;
6 7
 
7 8
 public class WC {
8
-    private Scanner sc;
9
+    private Iterator<String> si;
9 10
 
10 11
     public WC(String fileName) {
11 12
         try {
12
-            sc = new Scanner(new FileReader(fileName));
13
+            this.si = new Scanner(new FileReader(fileName));
13 14
         } catch (FileNotFoundException e) {
14 15
             System.out.println(fileName + " Does Not Exist");
15 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 Целия файл


+ 3
- 0
src/test/java/io/zipcoder/WCTest.java Целия файл

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