Browse Source

submitting lab

chitraB 6 years ago
parent
commit
0d5c5f55c2
4 changed files with 5508 additions and 3 deletions
  1. 12
    0
      pom.xml
  2. 94
    1
      src/main/java/HamletParser.java
  3. 19
    2
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml View File

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

+ 94
- 1
src/main/java/HamletParser.java View File

@@ -1,6 +1,8 @@
1 1
 import java.io.File;
2 2
 import java.io.IOException;
3 3
 import java.util.Scanner;
4
+import java.util.regex.Matcher;
5
+import java.util.regex.Pattern;
4 6
 
5 7
 /**
6 8
  * Created by thook on 10/7/15.
@@ -32,8 +34,99 @@ public class HamletParser {
32 34
         return result.toString();
33 35
     }
34 36
 
35
-    public String getHamletData(){
37
+    public static int changeHamletToLeon(String line){
38
+
39
+        int count=0;
40
+        Pattern patternHamlet =Pattern. compile("\\bHamlet\\b",Pattern.CASE_INSENSITIVE);
41
+        Matcher m1=patternHamlet.matcher(line);
42
+
43
+        String str1=((Matcher) m1).replaceAll("Leon");
44
+
45
+        Matcher m11=patternHamlet.matcher(str1);
46
+
47
+        while(m11.find())
48
+
49
+        {
50
+            count++;
51
+        }
52
+        return count;
53
+    }
54
+
55
+    public static int changeHoratioToTariq(String line) {
56
+
57
+        int count=0;
58
+
59
+        Pattern patternHoratio =Pattern.compile("\\bHoratio\\b",Pattern.CASE_INSENSITIVE);
60
+
61
+        Matcher m2=patternHoratio.matcher(line);
62
+
63
+        String str2=((Matcher) m2).replaceAll("Tariq");
64
+
65
+        Matcher m22=patternHoratio.matcher(str2);
66
+
67
+        while(m22.find())
68
+
69
+        {
70
+            count++;
71
+
72
+        }
73
+
74
+        return count;
75
+    }
76
+
77
+
78
+    public String getHamletData()
79
+
80
+    {
36 81
         return hamletData;
82
+
83
+    }
84
+
85
+    public int FindHoratio()
86
+
87
+    {
88
+        int count=0;
89
+
90
+        Pattern patternHoratio =Pattern.compile("\\bHoratio\\b",Pattern.CASE_INSENSITIVE);
91
+
92
+        Matcher m2=patternHoratio.matcher(hamletData);
93
+
94
+        while(m2.find())
95
+
96
+        {
97
+            count++;
98
+        }
99
+
100
+        return count;
101
+
37 102
     }
38 103
 
104
+    public int FindHamlet()
105
+
106
+    {
107
+        int count=0;
108
+
109
+        Pattern patternHamlet =Pattern.compile("\\bHamlet\\b",Pattern.CASE_INSENSITIVE);
110
+
111
+        Matcher m2=patternHamlet.matcher(hamletData);
112
+
113
+        while(m2.find())
114
+
115
+        {
116
+            count++;
117
+
118
+        }
119
+
120
+        return count;
121
+
122
+    }
123
+
124
+
125
+
126
+    public static void main(String[] args) {
127
+
128
+        HamletParser hamletParser=new HamletParser();
129
+    }
130
+
131
+
39 132
 }

+ 19
- 2
src/test/java/HamletParserTest.java View File

@@ -1,9 +1,11 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
4 5
 import static org.junit.Assert.*;
5 6
 
6 7
 public class HamletParserTest {
8
+
7 9
     private String hamletText;
8 10
     private HamletParser hamletParser;
9 11
 
@@ -14,18 +16,33 @@ public class HamletParserTest {
14 16
     }
15 17
 
16 18
     @Test
17
-    public void testChangeHamletToLeon() {
19
+    public void testChangeHamletToLeonCount() {
20
+
21
+        int expected =0;
22
+        int actual=hamletParser.changeHamletToLeon(hamletText);
23
+        assertEquals(expected, actual);
24
+
18 25
     }
19 26
 
27
+
20 28
     @Test
21
-    public void testChangeHoratioToTariq() {
29
+    public void testChangeHoratioToTariqCount() {
30
+        int expected=0;
31
+        int actual=hamletParser.changeHoratioToTariq(hamletText);
32
+        Assert.assertEquals(expected, actual);
22 33
     }
23 34
 
24 35
     @Test
25 36
     public void testFindHoratio() {
37
+        int expected=158;
38
+        int actual=hamletParser.FindHoratio();
39
+        Assert.assertEquals(expected, actual);
26 40
     }
27 41
 
28 42
     @Test
29 43
     public void testFindHamlet() {
44
+        int expected=471;
45
+        int actual=hamletParser.FindHamlet();
46
+        Assert.assertEquals(expected, actual);
30 47
     }
31 48
 }

+ 5383
- 0
target/classes/hamlet.txt
File diff suppressed because it is too large
View File