|
@@ -1,6 +1,7 @@
|
1
|
1
|
import java.io.File;
|
2
|
2
|
import java.io.IOException;
|
3
|
3
|
import java.util.Scanner;
|
|
4
|
+import java.util.regex.*;
|
4
|
5
|
|
5
|
6
|
/**
|
6
|
7
|
* Created by thook on 10/7/15.
|
|
@@ -36,4 +37,54 @@ public class HamletParser {
|
36
|
37
|
return hamletData;
|
37
|
38
|
}
|
38
|
39
|
|
|
40
|
+ public String changeHamletToLeon(String string) {
|
|
41
|
+ Pattern lowerCase = Pattern.compile("Hamlet");
|
|
42
|
+ Matcher match1 = lowerCase.matcher(string);
|
|
43
|
+ String result1 = match1.replaceAll("Leon");
|
|
44
|
+
|
|
45
|
+ Pattern upperCase = Pattern.compile("HAMLET");
|
|
46
|
+ Matcher match2 = upperCase.matcher(result1);
|
|
47
|
+ String result2 = match2.replaceAll("LEON");
|
|
48
|
+
|
|
49
|
+ return result2;
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ public String changeHoratioToTariq(String string) {
|
|
53
|
+ Pattern lowerCase = Pattern.compile("Horatio");
|
|
54
|
+ Matcher match1 = lowerCase.matcher(string);
|
|
55
|
+ String result1 = match1.replaceAll("Tariq");
|
|
56
|
+
|
|
57
|
+ Pattern upperCase = Pattern.compile("HORATIO");
|
|
58
|
+ Matcher match2 = upperCase.matcher(result1);
|
|
59
|
+ String result2 = match2.replaceAll("TARIQ");
|
|
60
|
+
|
|
61
|
+ return result2;
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ public boolean findHamlet(String input){
|
|
65
|
+ if ( hamletData.contains("Hamlet") || hamletData.contains("HAMLET")) {
|
|
66
|
+ }
|
|
67
|
+ return true;
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ public boolean findHoratio(String input){
|
|
71
|
+ if ( hamletData.contains("Horatio") || hamletData.contains("HORATIO")) {
|
|
72
|
+ }
|
|
73
|
+ return true;
|
|
74
|
+ }
|
|
75
|
+
|
39
|
76
|
}
|
|
77
|
+/*
|
|
78
|
+REGEX
|
|
79
|
+
|
|
80
|
+Directions
|
|
81
|
+
|
|
82
|
+Make a project that will go through the hamlet file provided and
|
|
83
|
+using regex replace every instance of "Hamlet" with "Leon" and every instance of Horatio with "Tariq".
|
|
84
|
+
|
|
85
|
+Beginning with tests, you are to program all the steps it will take to complete that process.
|
|
86
|
+Some tests have been stubbed out for you but
|
|
87
|
+these will not cover all the methods you should have in your project.
|
|
88
|
+
|
|
89
|
+IMPORTANT: You are not to use String Utilities to simply replace words. You must use Pattern and Matcher.
|
|
90
|
+ */
|