Kaynağa Gözat

Completed whole lab.

William Brown 6 yıl önce
ebeveyn
işleme
4bad4b8db7

BIN
.DS_Store Dosyayı Görüntüle


+ 15974
- 0
DRACULA
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 12
- 0
pom.xml Dosyayı Görüntüle

@@ -7,6 +7,18 @@
7 7
     <groupId>io.zipcoder</groupId>
8 8
     <artifactId>collections</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>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 1
- 0
someTextFile.txt Dosyayı Görüntüle

@@ -0,0 +1 @@
1
+1 2 3 4 5 6 7 6 45 4  5 6 7 8 6 54 45

BIN
src/.DS_Store Dosyayı Görüntüle


BIN
src/main/.DS_Store Dosyayı Görüntüle


+ 10
- 0
src/main/java/io/zipcoder/Main.java Dosyayı Görüntüle

@@ -0,0 +1,10 @@
1
+package io.zipcoder;
2
+
3
+public class Main {
4
+    public static void main(String[] args) {
5
+        //WC wc = new WC("someTextFile.txt");
6
+        WC wc = new WC("DRACULA");
7
+        wc.scanFile();
8
+        wc.sort();
9
+    }
10
+}

+ 154
- 0
src/main/java/io/zipcoder/ParenChecker.java Dosyayı Görüntüle

@@ -1,4 +1,158 @@
1 1
 package io.zipcoder;
2 2
 
3 3
 public class ParenChecker {
4
+
5
+//    () {} [] <> "" ''
6
+
7
+    public int doubleQuoteCount = 0;
8
+    public int singleQuoteCount = 0;
9
+
10
+
11
+    public boolean parensPaired(String input){
12
+        if(parensOpen(input) && parensClosed(input)){
13
+            return true;
14
+        }
15
+        return false;
16
+    }
17
+
18
+    public boolean parensOpen(String input){
19
+        for(int i = 0; i < input.length(); i++){
20
+            if(input.charAt(i) == '('){
21
+                return true;
22
+            }
23
+        }
24
+        return false;
25
+    }
26
+
27
+    public boolean parensClosed(String input){
28
+        int indexOfOpen = input.indexOf('(');
29
+        for(int i = indexOfOpen; i < input.length(); i++){
30
+            if(input.charAt(i) == ')'){
31
+                return true;
32
+            }
33
+        }
34
+        return false;
35
+    }
36
+
37
+
38
+
39
+
40
+
41
+    public boolean curlyPaired(String input){
42
+        if(curlyOpen(input) && curlyClosed(input)){
43
+            return true;
44
+        }
45
+        return false;
46
+    }
47
+
48
+    public boolean curlyOpen(String input){
49
+        for(int i = 0; i < input.length(); i++){
50
+            if(input.charAt(i) == '{'){
51
+                return true;
52
+            }
53
+        }
54
+        return false;
55
+    }
56
+
57
+    public boolean curlyClosed(String input){
58
+        int indexOfOpen = input.indexOf('{');
59
+        for(int i = indexOfOpen; i < input.length(); i++){
60
+            if(input.charAt(i) == '}'){
61
+                return true;
62
+            }
63
+        }
64
+        return false;
65
+    }
66
+
67
+
68
+
69
+
70
+
71
+    public boolean bracePaired(String input){
72
+        if(braceOpen(input) && braceClosed(input)){
73
+            return true;
74
+        }
75
+        return false;
76
+    }
77
+
78
+    public boolean braceOpen(String input){
79
+        for(int i = 0; i < input.length(); i++){
80
+            if(input.charAt(i) == '['){
81
+                return true;
82
+            }
83
+        }
84
+        return false;
85
+    }
86
+
87
+    public boolean braceClosed(String input){
88
+        int indexOfOpen = input.indexOf('[');
89
+        for(int i = indexOfOpen; i < input.length(); i++){
90
+            if(input.charAt(i) == ']'){
91
+                return true;
92
+            }
93
+        }
94
+        return false;
95
+    }
96
+
97
+
98
+
99
+
100
+
101
+    public boolean signsPaired(String input){
102
+        if(signsOpen(input) && signsClosed(input)){
103
+            return true;
104
+        }
105
+        return false;
106
+    }
107
+
108
+    public boolean signsOpen(String input){
109
+        for(int i = 0; i < input.length(); i++){
110
+            if(input.charAt(i) == '<'){
111
+                return true;
112
+            }
113
+        }
114
+        return false;
115
+    }
116
+
117
+    public boolean signsClosed(String input){
118
+        int indexOfOpen = input.indexOf('<');
119
+        for(int i = indexOfOpen; i < input.length(); i++){
120
+            if(input.charAt(i) == '>'){
121
+                return true;
122
+            }
123
+        }
124
+        return false;
125
+    }
126
+
127
+
128
+
129
+
130
+
131
+    public boolean doubleQuotePaired(String input) {
132
+        for(int i = 0; i < input.length(); i++){
133
+            if(input.charAt(i) == '\"'){
134
+                doubleQuoteCount++;
135
+            }
136
+        }
137
+        if(doubleQuoteCount % 2 == 0){
138
+            return true;
139
+        }
140
+        return false;
141
+    }
142
+
143
+
144
+
145
+
146
+
147
+    public boolean singleQuotePaired(String input) {
148
+        for(int i = 0; i < input.length(); i++){
149
+            if(input.charAt(i) == '\''){
150
+                singleQuoteCount++;
151
+            }
152
+        }
153
+        if(singleQuoteCount % 2 == 0){
154
+            return true;
155
+        }
156
+        return false;
157
+    }
4 158
 }

+ 34
- 5
src/main/java/io/zipcoder/WC.java Dosyayı Görüntüle

@@ -1,16 +1,17 @@
1 1
 package io.zipcoder;
2 2
 
3
-import java.io.FileNotFoundException;
4
-import java.io.FileReader;
5
-import java.util.Iterator;
6
-import java.util.Scanner;
3
+import java.io.*;
4
+import java.util.*;
7 5
 
8 6
 public class WC {
9 7
     private Iterator<String> si;
8
+    private Map<String, Integer> list = new HashMap<String, Integer>();
10 9
 
11 10
     public WC(String fileName) {
12 11
         try {
13
-            this.si = new Scanner(new FileReader(fileName));
12
+            Scanner scanner = new Scanner(new FileReader(fileName));
13
+            scanner.useDelimiter("[\\p{Punct}\\s]+");
14
+            this.si = scanner;
14 15
         } catch (FileNotFoundException e) {
15 16
             System.out.println(fileName + " Does Not Exist");
16 17
             System.exit(-1);
@@ -20,4 +21,32 @@ public class WC {
20 21
     public WC(Iterator<String> si) {
21 22
         this.si = si;
22 23
     }
24
+
25
+//    public static void main(String[] args) {
26
+//        //WC wc = new WC("someTextFile.txt");
27
+//        WC wc = new WC("DRACULA");
28
+//        wc.scanFile();
29
+//        wc.sort();
30
+//    }
31
+
32
+    public void scanFile(){
33
+        while(si.hasNext()){
34
+            String key = si.next().toLowerCase();
35
+            if(list.containsKey(key)){
36
+                list.put(key,list.get(key) + 1);
37
+            }else{
38
+                list.put(key, 1);
39
+            }
40
+        }
41
+
42
+    }
43
+
44
+    public void sort(){
45
+        list.entrySet()
46
+                .stream()
47
+                .sorted(Map.Entry.<String, Integer>comparingByValue()
48
+                .reversed())
49
+                .forEach(System.out::println);
50
+    }
51
+
23 52
 }

+ 0
- 0
src/main/resources/someTextFile.txt Dosyayı Görüntüle


+ 217
- 0
src/test/java/io/zipcoder/ParenCheckerTest.java Dosyayı Görüntüle

@@ -4,5 +4,222 @@ import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6 6
 public class ParenCheckerTest {
7
+    ParenChecker parenChecker = new ParenChecker();
8
+
9
+    @Test
10
+    public void testParenFalse1(){
11
+        String words = "This is a ( sentence.";
12
+
13
+        boolean actual = parenChecker.parensPaired(words);
14
+
15
+        Assert.assertFalse(actual);
16
+    }
17
+
18
+    @Test
19
+    public void testParenFalse2(){
20
+        String words = "This is a ) sentence.";
21
+
22
+        boolean actual = parenChecker.parensPaired(words);
23
+
24
+        Assert.assertFalse(actual);
25
+    }
26
+
27
+    @Test
28
+    public void testParenFalse3(){
29
+        String words = "This is a )( sentence.";
30
+
31
+        boolean actual = parenChecker.parensPaired(words);
32
+
33
+        Assert.assertFalse(actual);
34
+    }
35
+
36
+    @Test
37
+    public void testParenTrue1(){
38
+        String words = "This is a () sentence.";
39
+
40
+        boolean actual = parenChecker.parensPaired(words);
41
+
42
+        Assert.assertTrue(actual);
43
+    }
44
+
45
+    @Test
46
+    public void testParenTrue2(){
47
+        String words = "This (is a) sentence.";
48
+
49
+        boolean actual = parenChecker.parensPaired(words);
50
+
51
+        Assert.assertTrue(actual);
52
+    }
53
+
54
+    @Test
55
+    public void testCurlyFalse1(){
56
+        String words = "This is a { sentence.";
57
+
58
+        boolean actual = parenChecker.curlyPaired(words);
59
+
60
+        Assert.assertFalse(actual);
61
+    }
62
+
63
+    @Test
64
+    public void testCurlyFalse2(){
65
+        String words = "This is a } sentence.";
66
+
67
+        boolean actual = parenChecker.curlyPaired(words);
68
+
69
+        Assert.assertFalse(actual);
70
+    }
71
+
72
+    @Test
73
+    public void testCurlyFalse3(){
74
+        String words = "This is a }{ sentence.";
75
+
76
+        boolean actual = parenChecker.curlyPaired(words);
77
+
78
+        Assert.assertFalse(actual);
79
+    }
80
+
81
+    @Test
82
+    public void testCurlyTrue1(){
83
+        String words = "This is a {} sentence.";
84
+
85
+        boolean actual = parenChecker.curlyPaired(words);
86
+
87
+        Assert.assertTrue(actual);
88
+    }
89
+
90
+    @Test
91
+    public void testCurlyTrue2(){
92
+        String words = "This {is a} sentence.";
93
+
94
+        boolean actual = parenChecker.curlyPaired(words);
95
+
96
+        Assert.assertTrue(actual);
97
+    }
98
+
99
+    @Test
100
+    public void testBracketFalse1(){
101
+        String words = "This is a [ sentence.";
102
+
103
+        boolean actual = parenChecker.bracePaired(words);
104
+
105
+        Assert.assertFalse(actual);
106
+    }
107
+
108
+    @Test
109
+    public void testBracketFalse2(){
110
+        String words = "This is a ] sentence.";
111
+
112
+        boolean actual = parenChecker.bracePaired(words);
113
+
114
+        Assert.assertFalse(actual);
115
+    }
116
+
117
+    @Test
118
+    public void testBracketFalse3(){
119
+        String words = "This is a ][ sentence.";
120
+
121
+        boolean actual = parenChecker.bracePaired(words);
122
+
123
+        Assert.assertFalse(actual);
124
+    }
125
+
126
+    @Test
127
+    public void testBracketTrue1(){
128
+        String words = "This is a [] sentence.";
129
+
130
+        boolean actual = parenChecker.bracePaired(words);
131
+
132
+        Assert.assertTrue(actual);
133
+    }
134
+
135
+    @Test
136
+    public void testBracketTrue2(){
137
+        String words = "This [is a] sentence.";
138
+
139
+        boolean actual = parenChecker.bracePaired(words);
140
+
141
+        Assert.assertTrue(actual);
142
+    }
143
+
144
+    @Test
145
+    public void testThingsFalse1(){
146
+        String words = "This is a < sentence.";
147
+
148
+        boolean actual = parenChecker.signsPaired(words);
149
+
150
+        Assert.assertFalse(actual);
151
+    }
152
+
153
+    @Test
154
+    public void testThingsFalse2(){
155
+        String words = "This is a > sentence.";
156
+
157
+        boolean actual = parenChecker.signsPaired(words);
158
+
159
+        Assert.assertFalse(actual);
160
+    }
161
+
162
+    @Test
163
+    public void testThingsFalse3(){
164
+        String words = "This is a >< sentence.";
165
+
166
+        boolean actual = parenChecker.signsPaired(words);
167
+
168
+        Assert.assertFalse(actual);
169
+    }
170
+
171
+    @Test
172
+    public void testThingsTrue1(){
173
+        String words = "This is a <> sentence.";
174
+
175
+        boolean actual = parenChecker.signsPaired(words);
176
+
177
+        Assert.assertTrue(actual);
178
+    }
179
+
180
+    @Test
181
+    public void testThingsTrue2(){
182
+        String words = "This is a <i> sentence.";
183
+
184
+        boolean actual = parenChecker.signsPaired(words);
185
+
186
+        Assert.assertTrue(actual);
187
+    }
188
+
189
+    @Test
190
+    public void testDoubleQuotesFalse(){
191
+        String words = "This is a \"sentence.";
192
+
193
+        boolean actual = parenChecker.doubleQuotePaired(words);
194
+
195
+        Assert.assertFalse(actual);
196
+    }
197
+
198
+    @Test
199
+    public void testDoubleQuotesTrue(){
200
+        String words = "This\" is a \"sentence.";
201
+
202
+        boolean actual = parenChecker.doubleQuotePaired(words);
203
+
204
+        Assert.assertTrue(actual);
205
+    }
206
+
207
+    @Test
208
+    public void testSingleQuotesFalse(){
209
+        String words = "This is a \'sentence.";
210
+
211
+        boolean actual = parenChecker.singleQuotePaired(words);
212
+
213
+        Assert.assertFalse(actual);
214
+    }
215
+
216
+    @Test
217
+    public void testSingleQuotesTrue(){
218
+        String words = "This\' is a \'sentence.";
219
+
220
+        boolean actual = parenChecker.singleQuotePaired(words);
221
+
222
+        Assert.assertTrue(actual);
223
+    }
7 224
 
8 225
 }