|
@@ -1,6 +1,8 @@
|
1
|
1
|
package rocks.zipcode.io.quiz3.fundamentals;
|
2
|
2
|
|
3
|
3
|
import java.util.Arrays;
|
|
4
|
+import java.util.regex.Matcher;
|
|
5
|
+import java.util.regex.Pattern;
|
4
|
6
|
|
5
|
7
|
/**
|
6
|
8
|
* @author leon on 09/12/2018.
|
|
@@ -9,18 +11,15 @@ public class PigLatinGenerator {
|
9
|
11
|
private static final char[] vowels = {'a','e','i','o','u'};
|
10
|
12
|
public String translate(String str) {
|
11
|
13
|
String newWord = "";
|
|
14
|
+ String[] splitting = str.split(" ");
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+ Pattern firstVowelPattern = Pattern.compile("^([aeiouAEIOU])");
|
|
18
|
+ Matcher matcher = firstVowelPattern.matcher(str);
|
|
19
|
+ if (matcher.find()) return str + "way";
|
|
20
|
+ newWord = str.replaceAll("^([^aeiouAEIOU]*)(.+)", "$2$1ay");
|
|
21
|
+ return newWord;
|
|
22
|
+
|
12
|
23
|
|
13
|
|
-// if(str.startsWith("a") || str.startsWith("e") ||str.startsWith("i")
|
14
|
|
-// ||str.startsWith("o") ||str.startsWith("u")){
|
15
|
|
-// return newWord = str += "way";
|
16
|
|
-//
|
17
|
|
-// }else if(!str.startsWith("a")|| !str.startsWith("e") ||!str.startsWith("i")
|
18
|
|
-// ||!str.startsWith("o") ||!str.startsWith("u")){
|
19
|
|
-//
|
20
|
|
-// return newWord = str.substring(1) + str.charAt(0) + "ay";
|
21
|
|
-// }else{
|
22
|
|
-// return newWord;
|
23
|
|
-// }
|
24
|
|
-
|
25
|
24
|
}
|
26
|
25
|
}
|