Browse Source

add latest

Kate Moore 6 years ago
parent
commit
c1eb40106c

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

@@ -6,7 +6,7 @@ package rocks.zipcode.io.quiz3.arrays;
6 6
 public class SquareArrayAnalyzer {
7 7
     public static Boolean compare(Integer[] input, Integer[] squaredValues) {
8 8
         for(int i = 0; i < input.length; i++) {
9
-            if(input[i].equals(squaredValues[i])) {
9
+            if(input[i]!=(squaredValues[i])) {
10 10
                 return true;
11 11
             }
12 12
         }

+ 45
- 5
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java View File

@@ -20,25 +20,65 @@ public class TicTacToe {
20 20
     }
21 21
 
22 22
     public TicTacToe(String[][] board) {
23
+        this.board = board;
23 24
     }
24 25
 
25 26
     public String[] getRow(Integer value) {
26
-        return this.row;
27
+        String[] row = new String[3];
28
+        for(int i=0; i<row.length; i++) {
29
+            row[i] = board[value][i];
30
+        }
31
+        return row;
32
+
27 33
     }
28 34
 
29 35
     public String[] getColumn(Integer value) {
30
-        return this.column;
36
+        String[] column = new String[3];
37
+        for(int i=0; i<column.length; i++) {
38
+            column[i] = board[i][value];
39
+        }
40
+        return column;
41
+
31 42
     }
32 43
 
33 44
     public Boolean isRowHomogenous(Integer rowIndex) {
34
-        return null;
45
+        String[] row = new String[3];
46
+        for(int i=0; i<row.length; i++) {
47
+            row[i] = board[rowIndex][i];
48
+        }
49
+        if(row[0].equals(row[1]) && row[0].equals(row[2])){
50
+            return true;
51
+        }
52
+        return false;
35 53
     }
36 54
 
37 55
     public Boolean isColumnHomogeneous(Integer columnIndex) {
38
-        return null;
56
+        String[] column = new String[3];
57
+        for(int i=0; i<column.length; i++) {
58
+            column[i] = board[i][columnIndex];
59
+        }
60
+            if(column[0].equals(column[1]) && column[0].equals(column[2])){
61
+                return true;
62
+            }
63
+        return false;
39 64
     }
40 65
 
41 66
     public String getWinner() {
42
-        return null;
67
+        for (int i = 0; i < board.length; i++) {
68
+            for (int j = i; j < board.length; j++) {
69
+                if (board[i][j].equals("O")) {
70
+                    return "O";
71
+                } else if (board[i][j].equals("X")) {
72
+                    return "X";
73
+                } else if (board[j][i].equals("O")) {
74
+                    return "O";
75
+                } else if (board[j][i].equals("X")) {
76
+                    return "X";
77
+                }
78
+            }
79
+
80
+        }
81
+        return "X";
43 82
     }
83
+
44 84
 }

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

@@ -8,7 +8,10 @@ import java.util.ArrayList;
8 8
 public class WaveGenerator {
9 9
     public static String[] wave(String str) {
10 10
         ArrayList<String> waveList = new ArrayList<>();
11
-        String[] letters = str.split("");
11
+        for (int i = 0; i <str.length() ; i++) {
12
+            waveList.add(str);
13
+        }
14
+
12 15
 
13 16
 
14 17
         return null;

+ 12
- 0
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java View File

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

+ 12
- 0
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java View File

@@ -8,21 +8,33 @@ import java.util.Map;
8 8
  * @author leon on 10/12/2018.
9 9
  */
10 10
 public class Student {
11
+    Map<Lab, LabStatus> map;
12
+    Lab lab;
13
+    LabStatus labStatus;
14
+
15
+
11 16
     public Student() {
12 17
         this(null);
13 18
     }
14 19
 
15 20
     public Student(Map<Lab, LabStatus> map) {
21
+        this.map = map;
16 22
     }
17 23
 
18 24
     public void setLabStatus(Lab lab, LabStatus labStatus) {
25
+        this.lab = lab;
26
+        this.labStatus = labStatus;
19 27
     }
20 28
 
21 29
 
22 30
     public void forkLab(Lab lab) {
31
+        lab.setLabStatus("PENDING");
23 32
     }
24 33
 
25 34
     public LabStatus getLabStatus(String labName) {
26 35
         throw new UnsupportedOperationException("Method not yet implemented");
27 36
     }
37
+
38
+
39
+
28 40
 }

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

@@ -5,6 +5,27 @@ package rocks.zipcode.io.quiz3.fundamentals;
5 5
  */
6 6
 public class PigLatinGenerator {
7 7
     public String translate(String str) {
8
-        return null;
8
+        char a = 'a';
9
+        char e = 'e';
10
+        char ii = 'i';
11
+        char o = 'o';
12
+        char u = 'u';
13
+
14
+        int start = 0;
15
+        int firstVowel = 0;
16
+        int end = str.length();
17
+        for(int i = 0; i < end; i++) {
18
+            char c = Character.toLowerCase(str.charAt(i));
19
+            if(c == a || c == e || c == ii || c == o || c == u) {
20
+                firstVowel = i;
21
+                break;
22
+            }
23
+        }
24
+        if(start != firstVowel) {
25
+            String startString = str.substring(firstVowel, end);
26
+            String endString = str.substring(start, firstVowel) + "ay";
27
+            return startString+endString;
28
+        }
29
+        return str;
9 30
     }
10 31
 }

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

@@ -5,10 +5,15 @@ 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
+        String output = str.substring(indexToCapitalize, indexToCapitalize+1).toUpperCase() + str.substring(1);
9
+        return output;
10
+
9 11
     }
10 12
 
11 13
     public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
12
-        return null;
14
+            if(baseString.charAt(indexOfString) == characterToCheckFor) {
15
+                return true;
16
+            }
17
+        return false;
13 18
     }
14 19
 }

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

@@ -5,19 +5,44 @@ 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
+        String loweredWord = word.toLowerCase();
9
+        String vowels = "aeiou";
10
+        for (Integer i = 0; i < loweredWord.length(); i++) {
11
+            if (vowels.contains(String.valueOf(loweredWord.charAt(i)))) {
12
+                return true;
13
+            }
14
+        }
15
+        return false;
9 16
     }
10 17
 
11 18
     public static Integer getIndexOfFirstVowel(String word) {
19
+        String loweredWord = word.toLowerCase();
20
+        String vowels = "aeiou";
21
+        for (Integer i = 0; i < loweredWord.length(); i++) {
22
+            if (vowels.contains(String.valueOf(loweredWord.charAt(i)))) {
23
+                return i;
24
+            }
25
+        }
12 26
         return null;
13 27
     }
14 28
 
15 29
 
30
+
16 31
     public static Boolean startsWithVowel(String word) {
17
-        return null;
32
+            if(word.charAt(0)=='A'|| word.charAt(0)=='E'||word.charAt(0)=='I'||word.charAt(0)=='O'|| word.charAt(0)=='U'){
33
+                return true;
34
+            }
35
+        return false;
36
+
18 37
     }
19 38
 
20 39
     public static Boolean isVowel(Character character) {
21
-        return null;
40
+        char[] vowels = {'a','e','i', 'o','u'};
41
+        for (int i = 0; i <vowels.length ; i++) {
42
+            if(character == vowels[i]) {
43
+                return true;
44
+            }
45
+        }
46
+            return true;
22 47
     }
23 48
 }

+ 32
- 1
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java View File

@@ -1,11 +1,13 @@
1 1
 package rocks.zipcode.io.quiz3.generics;
2 2
 
3
+import java.util.ArrayList;
3 4
 import java.util.function.Function;
4 5
 
5 6
 /**
6 7
  * @author leon on 09/12/2018.
7 8
  */
8 9
 public class ArrayUtility<SomeType> {
10
+
9 11
     private final SomeType[] array;
10 12
 
11 13
     public ArrayUtility(SomeType[] array) {
@@ -13,15 +15,44 @@ public class ArrayUtility<SomeType> {
13 15
     }
14 16
 
15 17
     public SomeType findOddOccurringValue() {
18
+        Integer count = 0;
19
+        for(int i = 0; i<array.length; i++) {
20
+            for (int j = 0; j < array.length; j++) {
21
+                if (array[i] == array[j]) {
22
+                    count++;
23
+                }
24
+            }
25
+            if (count % 2 != 0) {
26
+                return array[i];
27
+            }
28
+        }
16 29
         return null;
17 30
     }
18 31
 
19 32
     public SomeType findEvenOccurringValue() {
33
+        Integer count = 0;
34
+        for(int i = 0; i<array.length; i++) {
35
+            for (int j = 0; j < array.length; j++) {
36
+                if (array[i] == array[j]) {
37
+                    count++;
38
+                }
39
+            }
40
+            if (count % 2 == 0) {
41
+                return array[i];
42
+            }
43
+        }
20 44
         return null;
21 45
     }
22 46
 
23 47
     public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
24
-        return null;
48
+        Integer count = 0;
49
+        for (int i = 0; i <array.length ; i++) {
50
+            if(array[i] == valueToEvaluate) {
51
+                count++;
52
+            }
53
+
54
+        }
55
+        return count;
25 56
     }
26 57
 
27 58
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {

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

@@ -4,5 +4,5 @@ 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
+    COMPLETED, PENDING, FORKED;
8 8
 }

+ 4
- 0
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/PAPER.java View File

@@ -0,0 +1,4 @@
1
+package rocks.zipcode.io.quiz3.objectorientation.enums;
2
+
3
+public enum PAPER {
4
+}

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

@@ -4,7 +4,9 @@ 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
+
8
+    ROCK, PAPER, SCISSOR;
9
+
8 10
 
9 11
     public RockPaperScissorHandSign getWinner() {
10 12
         return null;

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

@@ -12,7 +12,7 @@ public class IsCharacterAtIndex {
12 12
     public void test1() {
13 13
         // given
14 14
         String string = "Quickly";
15
-        Character character = 'q';
15
+        Character character = 'Q';
16 16
         Integer index = 0;
17 17
 
18 18
         // then
@@ -23,7 +23,7 @@ public class IsCharacterAtIndex {
23 23
     public void test2() {
24 24
         // given
25 25
         String string = "Quickly";
26
-        Character character = 'Q';
26
+        Character character = 'q';
27 27
         Integer index = 0;
28 28
 
29 29
         // then