Nick Satinover преди 6 години
родител
ревизия
53d248623c
променени са 3 файла, в които са добавени 32 реда и са изтрити 0 реда
  1. 12
    0
      pom.xml
  2. 16
    0
      src/main/java/HamletParser.java
  3. 4
    0
      src/test/java/HamletParserTest.java

+ 12
- 0
pom.xml Целия файл

@@ -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>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 16
- 0
src/main/java/HamletParser.java Целия файл

@@ -1,5 +1,6 @@
1 1
 import java.io.File;
2 2
 import java.io.IOException;
3
+import java.util.ArrayList;
3 4
 import java.util.Scanner;
4 5
 
5 6
 /**
@@ -8,6 +9,7 @@ import java.util.Scanner;
8 9
 public class HamletParser {
9 10
 
10 11
     private String hamletData;
12
+    String[] wordArr;
11 13
 
12 14
     public HamletParser(){
13 15
         this.hamletData = loadFile();
@@ -21,6 +23,12 @@ public class HamletParser {
21 23
         try(Scanner scanner = new Scanner(file)){
22 24
             while(scanner.hasNextLine()){
23 25
                 String line = scanner.nextLine();
26
+                if (isHamletOrHoratio(line)){
27
+                    wordArr = line.split(" ");
28
+                }
29
+                //loop through line for next
30
+                    //if next matches Hamlet, replace with Leon
31
+                    //if next matches Horatio, replace with Tariq
24 32
                 result.append(line).append("\n");
25 33
             }
26 34
 
@@ -36,4 +44,12 @@ public class HamletParser {
36 44
         return hamletData;
37 45
     }
38 46
 
47
+    public boolean isHamletOrHoratio(String line){
48
+        if (line.toLowerCase().matches("hamlet") || line.toLowerCase().matches("horatio")){
49
+            return true;
50
+        } else {
51
+            return false;
52
+        }
53
+    }
54
+
39 55
 }

+ 4
- 0
src/test/java/HamletParserTest.java Целия файл

@@ -1,3 +1,4 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
@@ -15,6 +16,9 @@ public class HamletParserTest {
15 16
 
16 17
     @Test
17 18
     public void testChangeHamletToLeon() {
19
+        //set to true to fail, change to false
20
+        Assert.assertTrue(hamletText.toLowerCase().contains("horatio"));
21
+        Assert.assertTrue(hamletText.toLowerCase().contains("hamlet"));
18 22
     }
19 23
 
20 24
     @Test