|
@@ -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.
|
|
@@ -36,4 +38,39 @@ public class HamletParser {
|
36
|
38
|
return hamletData;
|
37
|
39
|
}
|
38
|
40
|
|
|
41
|
+
|
|
42
|
+ public int findHamlet() {
|
|
43
|
+ Pattern pattern = Pattern.compile("(?i)Hamlet");
|
|
44
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
45
|
+ int count = 0;
|
|
46
|
+
|
|
47
|
+ while (matcher.find()) {
|
|
48
|
+ count++;
|
|
49
|
+ }
|
|
50
|
+ return count;
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ public int findHoratio() {
|
|
54
|
+ Pattern pattern = Pattern.compile("(?i)Horatio");
|
|
55
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
56
|
+ int count = 0;
|
|
57
|
+
|
|
58
|
+ while (matcher.find()){
|
|
59
|
+ count++;
|
|
60
|
+ }
|
|
61
|
+ return count;
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ public String changeHamletToLeon() {
|
|
65
|
+
|
|
66
|
+ Pattern pattern = Pattern.compile(hamletData);
|
|
67
|
+ Matcher matcher = pattern.matcher("Leon");
|
|
68
|
+ return matcher.replaceAll("Hamlet");
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ public String changeHoratioToTariq() {
|
|
72
|
+ Pattern pattern = Pattern.compile(hamletData);
|
|
73
|
+ Matcher matcher = pattern.matcher("Tariq");
|
|
74
|
+ return matcher.replaceAll("Horatio");
|
|
75
|
+ }
|
39
|
76
|
}
|