Przeglądaj źródła

hamlets leon'd, horatios tariq'd

NedRedmond 6 lat temu
rodzic
commit
4d91ddd4fc

+ 28
- 0
src/main/java/HamletCorrector.java Wyświetl plik

@@ -0,0 +1,28 @@
1
+import java.util.regex.Matcher;
2
+import java.util.regex.Pattern;
3
+
4
+public class HamletCorrector {
5
+
6
+    public static void main(String[] args) {
7
+
8
+        HamletParser ham = new HamletParser();
9
+        String text = ham.getHamletData();
10
+
11
+        Matcher hamMatcher = matchPattern("(Hamlet)+|(HAMLET)+", text);
12
+        String newText = replaceMatch(hamMatcher, "LEON");
13
+        Matcher horMatcher = matchPattern("(Horatio)+|(HORATIO)+", newText);
14
+        String finalText = replaceMatch(horMatcher, "TARIQ");
15
+
16
+        System.out.println(finalText);
17
+    }
18
+
19
+    private static String replaceMatch(Matcher m, String textToReplace) {
20
+        return m.replaceAll(textToReplace);
21
+    }
22
+
23
+    private static Matcher matchPattern(String regex, String text) {
24
+        Pattern pattern = Pattern.compile(regex);
25
+        return pattern.matcher(text);
26
+    }
27
+
28
+}

+ 0
- 1
src/main/java/HamletParser.java Wyświetl plik

@@ -24,7 +24,6 @@ public class HamletParser {
24 24
                 result.append(line).append("\n");
25 25
             }
26 26
 
27
-            scanner.close();
28 27
         }catch(IOException e){
29 28
             e.printStackTrace();
30 29
         }

+ 5383
- 0
target/classes/hamlet.txt
Plik diff jest za duży
Wyświetl plik