Seth 6 år sedan
förälder
incheckning
939897636d

+ 9
- 1
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java Visa fil

@@ -5,6 +5,14 @@ package rocks.zipcode.io.quiz3.fundamentals;
5 5
  */
6 6
 public class PigLatinGenerator {
7 7
     public String translate(String str) {
8
-        return null;
8
+        if (VowelUtils.startsWithVowel(str)){
9
+            return str + "way";
10
+        } else if (VowelUtils.hasVowels(str)){
11
+            int index = VowelUtils.getIndexOfFirstVowel(str);
12
+            return str.substring(index) + str.substring(0, index) + "ay";
13
+        } else{
14
+           return str + "ay";
15
+        }
9 16
     }
17
+
10 18
 }

+ 7
- 2
src/main/java/rocks/zipcode/io/quiz3/fundamentals/VowelUtils.java Visa fil

@@ -17,8 +17,13 @@ public class VowelUtils {
17 17
     }
18 18
 
19 19
     public static Integer getIndexOfFirstVowel(String word) {
20
-
21
-        return -1;
20
+        String vowels = "aiueo";
21
+        for (int i = 0; i < word.length(); i++) {
22
+            if (vowels.contains(String.valueOf(word.charAt(i)))){
23
+                return i;
24
+            }
25
+        }
26
+        return null;
22 27
     }
23 28
 
24 29