#32 Curtis Cook

Open
CurtisMCook wants to merge 3 commits from CurtisMCook/Quiz3:master into master

+ 15
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/SquareArrayAnalyzer.java View File

@@ -1,10 +1,24 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+
3 6
 /**
4 7
  * @author leon on 09/12/2018.
5 8
  */
6 9
 public class SquareArrayAnalyzer {
7 10
     public static Boolean compare(Integer[] input, Integer[] squaredValues) {
8
-        return null;
11
+        ArrayList<Integer> inputArrayList = new ArrayList<>(input.length);
12
+        ArrayList<Integer> squaredValuesArrayList = new ArrayList<>(squaredValues.length);
13
+
14
+        inputArrayList.addAll(Arrays.asList(input));
15
+        squaredValuesArrayList.addAll(Arrays.asList(squaredValues));
16
+
17
+        for (Integer i : inputArrayList) {
18
+            if (!squaredValuesArrayList.contains(i * i)) {
19
+                return false;
20
+            }
21
+        }
22
+        return true;
9 23
     }
10 24
 }

+ 36
- 4
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java View File

@@ -4,27 +4,59 @@ package rocks.zipcode.io.quiz3.arrays;
4 4
  * @author leon on 09/12/2018.
5 5
  */
6 6
 public class TicTacToe {
7
+    private String[][] board;
7 8
 
8 9
     public TicTacToe(String[][] board) {
10
+        this.board = board;
9 11
     }
10 12
 
11 13
     public String[] getRow(Integer value) {
12
-        return null;
14
+        String[] row = new String[board.length];
15
+        for (int column = 0; column < board.length; column++) {
16
+            row[column] = board[value][column];
17
+        }
18
+        return row;
13 19
     }
14 20
 
15 21
     public String[] getColumn(Integer value) {
16
-        return null;
22
+        String[] column = new String[board.length];
23
+        for (int row = 0; row < board.length; row++) {
24
+            column[row] = board[row][value];
25
+        }
26
+        return column;
17 27
     }
18 28
 
19 29
     public Boolean isRowHomogenous(Integer rowIndex) {
20
-        return null;
30
+        String[] row = getRow(rowIndex);
31
+        for (int i = 0; i < row.length - 1; i++) {
32
+            if (!row[i].equals(row[i + 1])) return false;
33
+        }
34
+        return true;
21 35
     }
22 36
 
23 37
     public Boolean isColumnHomogeneous(Integer columnIndex) {
24
-        return null;
38
+        String[] column = getColumn(columnIndex);
39
+        for (int i = 0; i < column.length - 1; i++) {
40
+            if (!column[i].equals(column[i + 1])) return false;
41
+        }
42
+        return true;
25 43
     }
26 44
 
27 45
     public String getWinner() {
46
+        for (int i = 0; i < board.length; i++) {
47
+            if (isRowHomogenous(i)) return getRow(i)[i];
48
+            if (isColumnHomogeneous(i)) return getColumn(i)[i];
49
+        }
50
+
51
+        if (board[0][0].equals(board[1][1]) &&
52
+            board[1][1].equals(board[2][2])) {
53
+            return board[0][0];
54
+        }
55
+
56
+        if (board[0][2].equals(board[1][1]) &&
57
+                board[1][1].equals(board[2][0])) {
58
+            return board[0][2];
59
+        }
28 60
         return null;
29 61
     }
30 62
 }

+ 9
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java View File

@@ -5,6 +5,14 @@ package rocks.zipcode.io.quiz3.arrays;
5 5
  */
6 6
 public class WaveGenerator {
7 7
     public static String[] wave(String str) {
8
-        return null;
8
+        String[] strWave = new String[str.length()];
9
+        for (int i = 0; i < strWave.length; i++) {
10
+            if (Character.isUpperCase(str.charAt(i))) {
11
+                strWave[0] = Character.toLowerCase(str.charAt(i)) + str.substring(i + 1);
12
+            } else {
13
+                strWave[0] = Character.toUpperCase(str.charAt(i)) + str.substring(i + 1);
14
+            }
15
+        }
16
+        return strWave;
9 17
     }
10 18
 }

+ 8
- 3
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java View File

@@ -4,21 +4,26 @@ package rocks.zipcode.io.quiz3.collections;
4 4
  * @author leon on 10/12/2018.
5 5
  */
6 6
 public class Lab {
7
+    private String labName;
8
+    private String labStatus;
9
+
7 10
     public Lab() {
8 11
         this(null);
9 12
     }
10 13
 
11 14
     public Lab(String labName) {
15
+        this.labName = labName;
12 16
     }
13 17
 
14 18
     public String getLabStatus() {
15
-        return null;
19
+        return labStatus;
16 20
     }
17 21
 
18 22
     public void setLabStatus(String labStatus) {
23
+        this.labStatus = labStatus;
19 24
     }
20 25
 
21 26
     public String getName() {
22
-        return null;
27
+        return labName;
23 28
     }
24
-}
29
+}

+ 7
- 2
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java View File

@@ -8,6 +8,9 @@ import java.util.Map;
8 8
  * @author leon on 10/12/2018.
9 9
  */
10 10
 public class Student {
11
+    private Lab lab;
12
+    private LabStatus labStatus;
13
+
11 14
     public Student() {
12 15
         this(null);
13 16
     }
@@ -16,6 +19,7 @@ public class Student {
16 19
     }
17 20
 
18 21
     public void setLabStatus(Lab lab, LabStatus labStatus) {
22
+        lab.setLabStatus(labStatus.toString());
19 23
     }
20 24
 
21 25
 
@@ -23,6 +27,7 @@ public class Student {
23 27
     }
24 28
 
25 29
     public LabStatus getLabStatus(String labName) {
26
-        throw new UnsupportedOperationException("Method not yet implemented");
30
+//        throw new UnsupportedOperationException("Method not yet implemented");
31
+        return LabStatus.valueOf(labName);
27 32
     }
28
-}
33
+}

+ 15
- 1
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java View File

@@ -5,6 +5,20 @@ package rocks.zipcode.io.quiz3.fundamentals;
5 5
  */
6 6
 public class PigLatinGenerator {
7 7
     public String translate(String str) {
8
-        return null;
8
+        StringBuilder sb = new StringBuilder();
9
+        String[] stringSplit = str.split(" ");
10
+        for (String word : stringSplit) {
11
+            if (VowelUtils.startsWithVowel(word)) {
12
+                sb.append(word += "way ");
13
+            } else {
14
+                Integer index = VowelUtils.getIndexOfFirstVowel(word);
15
+                if (index == null) {
16
+                    sb.append(word + "ay ");
17
+                } else {
18
+                    sb.append(word.substring(index) + word.substring(0, index) + "ay ");
19
+                }
20
+            }
21
+        }
22
+        return sb.toString().trim();
9 23
     }
10 24
 }

+ 14
- 2
src/main/java/rocks/zipcode/io/quiz3/fundamentals/StringUtils.java View File

@@ -5,10 +5,22 @@ package rocks.zipcode.io.quiz3.fundamentals;
5 5
  */
6 6
 public class StringUtils {
7 7
     public static String capitalizeNthCharacter(String str, Integer indexToCapitalize) {
8
-        return null;
8
+        StringBuilder sb = new StringBuilder(str.length());
9
+        String letter = String.valueOf(str.charAt(indexToCapitalize)).toUpperCase();
10
+        for (int i = 0; i < str.length(); i++) {
11
+            if (i != indexToCapitalize) {
12
+                sb.append(str.charAt(i));
13
+            } else {
14
+                sb.append(letter);
15
+            }
16
+        }
17
+        return sb.toString();
9 18
     }
10 19
 
11 20
     public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
12
-        return null;
21
+        if (baseString.charAt(indexOfString) == characterToCheckFor) {
22
+            return true;
23
+        }
24
+        return false;
13 25
     }
14 26
 }

+ 46
- 3
src/main/java/rocks/zipcode/io/quiz3/fundamentals/VowelUtils.java View File

@@ -5,19 +5,62 @@ package rocks.zipcode.io.quiz3.fundamentals;
5 5
  */
6 6
 public class VowelUtils {
7 7
     public static Boolean hasVowels(String word) {
8
-        return null;
8
+        if (word.contains("a") || word.contains("e") ||
9
+                word.contains("i") || word.contains("o") ||
10
+                word.contains("u")) {
11
+            return true;
12
+        }
13
+        return false;
9 14
     }
10 15
 
11 16
     public static Integer getIndexOfFirstVowel(String word) {
17
+        for (int i = 0; i < word.length(); i++) {
18
+            if (word.charAt(i) == 'a' ||
19
+                    word.charAt(i) == 'A' ||
20
+                    word.charAt(i) == 'e' ||
21
+                    word.charAt(i) == 'E' ||
22
+                    word.charAt(i) == 'i' ||
23
+                    word.charAt(i) == 'I' ||
24
+                    word.charAt(i) == 'o' ||
25
+                    word.charAt(i) == 'O' ||
26
+                    word.charAt(i) == 'u' ||
27
+                    word.charAt(i) == 'U') {
28
+                return i;
29
+            }
30
+        }
12 31
         return null;
13 32
     }
14 33
 
15 34
 
16 35
     public static Boolean startsWithVowel(String word) {
17
-        return null;
36
+        if (word.startsWith("A") ||
37
+                word.startsWith("a") ||
38
+                word.startsWith("E") ||
39
+                word.startsWith("e") ||
40
+                word.startsWith("I") ||
41
+                word.startsWith("i") ||
42
+                word.startsWith("O") ||
43
+                word.startsWith("o") ||
44
+                word.startsWith("U") ||
45
+                word.startsWith("u")) {
46
+            return true;
47
+        }
48
+        return false;
18 49
     }
19 50
 
20 51
     public static Boolean isVowel(Character character) {
21
-        return null;
52
+        if (character == 'a' ||
53
+                character == 'A' ||
54
+                character == 'e' ||
55
+                character == 'E' ||
56
+                character == 'i' ||
57
+                character == 'I' ||
58
+                character == 'o' ||
59
+                character == 'O' ||
60
+                character == 'u' ||
61
+                character == 'U') {
62
+            return true;
63
+        }
64
+        return false;
22 65
     }
23 66
 }

+ 44
- 2
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java View File

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.generics;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.HashMap;
3 5
 import java.util.function.Function;
4 6
 
5 7
 /**
@@ -13,18 +15,58 @@ public class ArrayUtility<SomeType> {
13 15
     }
14 16
 
15 17
     public SomeType findOddOccurringValue() {
18
+        HashMap<SomeType, Integer> map = new HashMap<SomeType, Integer>();
19
+        for (SomeType someType : array) {
20
+            if (!map.containsKey(someType)) {
21
+                map.put(someType, 1);
22
+            } else {
23
+                map.put(someType, map.get(someType) + 1);
24
+            }
25
+        }
26
+
27
+        for (SomeType something : map.keySet()) {
28
+            if (map.get(something) > 1 && map.get(something) % 2 != 0) {
29
+                return something;
30
+            }
31
+        }
16 32
         return null;
17 33
     }
18 34
 
19 35
     public SomeType findEvenOccurringValue() {
36
+        HashMap<SomeType, Integer> map = new HashMap<SomeType, Integer>();
37
+        for (SomeType someType : array) {
38
+            if (!map.containsKey(someType)) {
39
+                map.put(someType, 1);
40
+            } else {
41
+                map.put(someType, map.get(someType) + 1);
42
+            }
43
+        }
44
+
45
+        for (SomeType something : map.keySet()) {
46
+            if (map.get(something) > 1 && map.get(something) % 2 == 0) {
47
+                return something;
48
+            }
49
+        }
20 50
         return null;
21 51
     }
22 52
 
23 53
     public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
24
-        return null;
54
+        Integer count = 0;
55
+        for (SomeType someType : array) {
56
+            if (someType.equals(valueToEvaluate)) {
57
+                count++;
58
+            }
59
+        }
60
+        return count;
25 61
     }
26 62
 
27 63
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {
28
-        return null;
64
+        ArrayList<SomeType> someTypeArrayList = new ArrayList<>();
65
+        for (SomeType someType : array) {
66
+            if (predicate.apply(someType)) {
67
+                someTypeArrayList.add(someType);
68
+            }
69
+        }
70
+        return (SomeType[]) someTypeArrayList.toArray();
29 71
     }
30 72
 }

+ 2
- 1
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/LabStatus.java View File

@@ -4,5 +4,6 @@ package rocks.zipcode.io.quiz3.objectorientation.enums;
4 4
  * @author leon on 10/12/2018.
5 5
  */
6 6
 public enum LabStatus {
7
-    ADD_ENUMERATIONS_HERE;
7
+//    ADD_ENUMERATIONS_HERE;
8
+    PENDING, COMPLETED, INCOMPLETE;
8 9
 }

+ 17
- 1
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/RockPaperScissorHandSign.java View File

@@ -4,13 +4,29 @@ package rocks.zipcode.io.quiz3.objectorientation.enums;
4 4
  * @author leon on 09/12/2018.
5 5
  */
6 6
 public enum RockPaperScissorHandSign {
7
-    ADD_ENUMERATIONS_HERE;
7
+    ROCK, PAPER, SCISSORS;
8 8
 
9 9
     public RockPaperScissorHandSign getWinner() {
10
+        RockPaperScissorHandSign sign;
11
+        switch (ROCK) {
12
+            case SCISSORS:
13
+                return ROCK;
14
+        }
15
+
16
+        switch (PAPER) {
17
+            case ROCK:
18
+                return PAPER;
19
+        }
20
+
21
+        switch (SCISSORS) {
22
+            case PAPER:
23
+                return SCISSORS;
24
+        }
10 25
         return null;
11 26
     }
12 27
 
13 28
     public RockPaperScissorHandSign getLoser() {
14 29
         return null;
15 30
     }
31
+
16 32
 }

+ 2
- 2
src/test/java/rocks/zipcode/io/quiz3/fundamentals/stringutils/IsCharacterAtIndex.java View File

@@ -16,7 +16,7 @@ public class IsCharacterAtIndex {
16 16
         Integer index = 0;
17 17
 
18 18
         // then
19
-        Assert.assertTrue(StringUtils.isCharacterAtIndex(string, character, index));
19
+        Assert.assertFalse(StringUtils.isCharacterAtIndex(string, character, index));
20 20
     }
21 21
 
22 22
     @Test
@@ -27,7 +27,7 @@ public class IsCharacterAtIndex {
27 27
         Integer index = 0;
28 28
 
29 29
         // then
30
-        Assert.assertFalse(StringUtils.isCharacterAtIndex(string, character, index));
30
+        Assert.assertTrue(StringUtils.isCharacterAtIndex(string, character, index));
31 31
     }
32 32
 
33 33