Saurav Kamath il y a 7 ans
Parent
révision
555e028869

+ 1
- 1
README.md Voir le fichier

@@ -1,4 +1,4 @@
1
-# Pig Latin blah
1
+# Pig Latin
2 2
 * Pig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules.
3 3
 * The rules themselves are rather easy:
4 4
 * 1) The word starts with a vowel(a,e,i,o,u) -> return the original string plus "way".

+ 8
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/SquareArrayAnalyzer.java Voir le fichier

@@ -5,6 +5,13 @@ package rocks.zipcode.io.quiz3.arrays;
5 5
  */
6 6
 public class SquareArrayAnalyzer {
7 7
     public static Boolean compare(Integer[] input, Integer[] squaredValues) {
8
-        return null;
8
+        int count = 0;
9
+        for(int i = 0; i < input.length; i++){
10
+            Integer square = input[i]*input[i];
11
+            if(square.equals(squaredValues[i])){
12
+                count+=1;
13
+            }
14
+        }
15
+        return count == squaredValues.length;
9 16
     }
10 17
 }

+ 20
- 4
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java Voir le fichier

@@ -1,27 +1,43 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 /**
4 6
  * @author leon on 09/12/2018.
5 7
  */
6 8
 public class TicTacToe {
9
+    private String[][] board;
7 10
 
8 11
     public TicTacToe(String[][] board) {
12
+        this.board = board;
9 13
     }
10 14
 
11 15
     public String[] getRow(Integer value) {
12
-        return null;
16
+        return board[value];
13 17
     }
14 18
 
15 19
     public String[] getColumn(Integer value) {
16
-        return null;
20
+        String[] column = new String[3];
21
+        column[0] = board[0][value];
22
+        column[1] = board[1][value];
23
+        column[2] = board[2][value];
24
+        return column;
17 25
     }
18 26
 
19 27
     public Boolean isRowHomogenous(Integer rowIndex) {
20
-        return null;
28
+        String check = this.getRow(rowIndex)[0];
29
+        if(!this.getRow(rowIndex)[1].equals(check) || !this.getRow(rowIndex)[2].equals(check)){
30
+            return false;
31
+        }
32
+        return true;
21 33
     }
22 34
 
23 35
     public Boolean isColumnHomogeneous(Integer columnIndex) {
24
-        return null;
36
+        String check = this.getColumn(columnIndex)[0];
37
+        if(!this.getColumn(columnIndex)[1].equals(check) || !this.getColumn(columnIndex)[2].equals(check)){
38
+            return false;
39
+        }
40
+        return true;
25 41
     }
26 42
 
27 43
     public String getWinner() {

+ 29
- 2
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java Voir le fichier

@@ -1,10 +1,37 @@
1 1
 package rocks.zipcode.io.quiz3.fundamentals;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 /**
4 6
  * @author leon on 09/12/2018.
5 7
  */
6 8
 public class PigLatinGenerator {
9
+    private static final char[] vowels = {'a', 'e', 'i', 'o', 'u'};
7 10
     public String translate(String str) {
8
-        return null;
11
+        String fin = "";
12
+        String[] wordArr = str.split(" ");
13
+        for(String word : wordArr){
14
+            fin = fin.concat(translateWord(word));
15
+        }
16
+        return fin;
17
+    }
18
+    public String translateWord(String word){
19
+            int start = 0; // start index of word
20
+            int firstVowel = 0;
21
+            int end = word.length(); // end index of word
22
+            for(int i = 0; i < end; i++) { // loop over length of word
23
+                char c = Character.toLowerCase(word.charAt(i)); // char of word at i, lower cased
24
+                if(Arrays.asList(vowels).contains(c)) { // convert vowels to a list so we can use List.contains() convenience method.
25
+                    firstVowel = i;
26
+                    break;
27
+                }
28
+            }
29
+            if(start != firstVowel) { // if start is not equal to firstVowel, we caught a vowel.
30
+                String startString = word.substring(firstVowel, end);
31
+                String endString = word.substring(start, firstVowel) + "ay";
32
+                return startString+endString;
33
+            }
34
+            return word; //couldn't find a
35
+        }
9 36
     }
10
-}
37
+