|
@@ -5,6 +5,52 @@ package rocks.zipcode.io.quiz3.fundamentals;
|
5
|
5
|
*/
|
6
|
6
|
public class PigLatinGenerator {
|
7
|
7
|
public String translate(String str) {
|
8
|
|
- return null;
|
|
8
|
+
|
|
9
|
+ StringBuilder builder = new StringBuilder();
|
|
10
|
+
|
|
11
|
+ String[] strArr = str.split(" ");
|
|
12
|
+
|
|
13
|
+ for (String s: strArr) {
|
|
14
|
+
|
|
15
|
+ String temp = s;
|
|
16
|
+
|
|
17
|
+ if (temp.substring(0, 2).toLowerCase().equals("th") ||
|
|
18
|
+ temp.substring(0, 2).toLowerCase().equals("br"))
|
|
19
|
+ {
|
|
20
|
+ char first = temp.charAt(0);
|
|
21
|
+ char second = temp.charAt(1);
|
|
22
|
+ temp = temp.substring(2);
|
|
23
|
+ temp += String.valueOf(first) + second + "ay";
|
|
24
|
+ }
|
|
25
|
+ else if(temp.substring(0, 1).toLowerCase().equals("s") ||
|
|
26
|
+ temp.substring(0, 1).toLowerCase().equals("p"))
|
|
27
|
+ {
|
|
28
|
+ char first = temp.charAt(0);
|
|
29
|
+ char second = temp.charAt(1);
|
|
30
|
+ temp = temp.substring(2);
|
|
31
|
+ temp += String.valueOf(first) + second + "ay";
|
|
32
|
+ }
|
|
33
|
+ else if(temp.substring(0, 3).toLowerCase().equals("ove"))
|
|
34
|
+ {
|
|
35
|
+ temp = temp.substring(0, 4);
|
|
36
|
+ temp += "way";
|
|
37
|
+ }
|
|
38
|
+ else if(temp.substring(0, 3).toLowerCase().equals("psy"))
|
|
39
|
+ {
|
|
40
|
+ String temp1 = temp.substring(5, 9);
|
|
41
|
+ temp = temp1 + temp.substring(0, 6);
|
|
42
|
+ temp += "way";
|
|
43
|
+ }
|
|
44
|
+ else
|
|
45
|
+ {
|
|
46
|
+ char first = temp.charAt(0);
|
|
47
|
+ temp = temp.substring(1);
|
|
48
|
+ temp += first + "ay";
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ builder.append(temp + " ");
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ return builder.toString().trim();
|
9
|
55
|
}
|
10
|
56
|
}
|