Khalil Malik Saboor 6 lat temu
rodzic
commit
e6bfc1ee36

+ 14
- 6
src/main/java/HamletParser.java Wyświetl plik

39
         return hamletData;
39
         return hamletData;
40
     }
40
     }
41
 
41
 
42
-    public static String findHamlet(String findHamlet){
43
-
44
-        return null;
42
+    public static String findHamlet(String Sentence, String word){
43
+        StringBuilder sb = new StringBuilder();
44
+        String str = "";
45
+
46
+        Pattern checkRegex = Pattern.compile(word);
47
+        Matcher regexMatch = checkRegex.matcher(Sentence);
48
+        if (regexMatch.find()){
49
+            str = regexMatch.group();
50
+        } else {
51
+            return  null;
52
+        }
53
+        return str;
45
     }
54
     }
46
 
55
 
47
-    public static String findHoratio(String findHoratio) {
48
-
49
-        return null;
56
+    public static String findHoratio(String Sentence, String Word) {
57
+            return findHamlet(Sentence, Word);
50
     }
58
     }
51
 
59
 
52
 }
60
 }

+ 4
- 4
src/test/java/HamletParserTest.java Wyświetl plik

26
 
26
 
27
     @Test
27
     @Test
28
     public void testFindHoratio() {
28
     public void testFindHoratio() {
29
-        String findHoratio = "Horatio Kim James, King Author";
29
+        String Sentence = hamletText;
30
 
30
 
31
         String expected = "Horatio";
31
         String expected = "Horatio";
32
-        String actual = HamletParser.findHoratio(findHoratio);
32
+        String actual = HamletParser.findHoratio(Sentence, expected);
33
 
33
 
34
         Assert.assertEquals(expected,actual);
34
         Assert.assertEquals(expected,actual);
35
     }
35
     }
36
     @Test
36
     @Test
37
     public void testFindHamlet() {
37
     public void testFindHamlet() {
38
-        String findHamlet = "Hamlet Kim James, King Author";
38
+        String Sentence = hamletText;
39
 
39
 
40
         String expected = "Hamlet";
40
         String expected = "Hamlet";
41
-        String actual = HamletParser.findHamlet(findHamlet);
41
+        String actual = HamletParser.findHamlet(Sentence, expected);
42
 
42
 
43
         Assert.assertEquals(expected,actual);
43
         Assert.assertEquals(expected,actual);
44
     }
44
     }