#33 Steffon Williams

開啟中
Stwillia94 請求將 3 次程式碼提交從 Stwillia94/Quiz3:master 合併至 master

+ 8
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/SquareArrayAnalyzer.java 查看文件

@@ -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
+
9
+        for (Integer i : input)
10
+            for (Integer j : squaredValues)
11
+                if (i * i == j)
12
+                    return true;
13
+
14
+        return false;
15
+
9 16
     }
10 17
 }

+ 50
- 5
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java 查看文件

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

+ 12
- 0
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java 查看文件

@@ -1,10 +1,22 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+import rocks.zipcode.io.quiz3.fundamentals.StringUtils;
4
+
5
+import java.util.stream.IntStream;
6
+
3 7
 /**
4 8
  * @author leon on 09/12/2018.
5 9
  */
6 10
 public class WaveGenerator {
7 11
     public static String[] wave(String str) {
12
+        //String repeated
13
+       StringBuilder sb = new StringBuilder(str);
14
+
15
+       for(int i = 0; i < 7; i++)
16
+           sb.append(str);
17
+
18
+
19
+
8 20
         return null;
9 21
     }
10 22
 }

+ 13
- 2
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java 查看文件

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

+ 8
- 2
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java 查看文件

@@ -5,6 +5,12 @@ package rocks.zipcode.io.quiz3.fundamentals;
5 5
  */
6 6
 public class PigLatinGenerator {
7 7
     public String translate(String str) {
8
-        return null;
8
+
9
+       return null;
9 10
     }
10
-}
11
+
12
+
13
+
14
+
15
+    }
16
+

+ 17
- 3
src/main/java/rocks/zipcode/io/quiz3/fundamentals/StringUtils.java 查看文件

@@ -5,10 +5,24 @@ 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;
9
-    }
8
+  char[] arr = str.toCharArray();
9
+  arr[indexToCapitalize] = Character.toUpperCase(arr[indexToCapitalize]);
10
+
11
+  String newStr = new String(arr);
12
+
13
+     return newStr;
14
+          }
15
+
16
+
10 17
 
11 18
     public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
12
-        return null;
19
+
20
+        String newStr = baseString.toLowerCase();
21
+
22
+
23
+       if(newStr.charAt(indexOfString) != characterToCheckFor)
24
+           return false;
25
+
26
+        return true;
13 27
     }
14 28
 }

+ 33
- 4
src/main/java/rocks/zipcode/io/quiz3/fundamentals/VowelUtils.java 查看文件

@@ -5,19 +5,48 @@ 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 vowels = "aeiou";
9
+
10
+       for(int i = 0; i < word.length();i++)
11
+           for(int j = 0; j < vowels.length(); j++)
12
+               if(word.charAt(i) == vowels.charAt(j))
13
+                   return  true;
14
+               return false;
15
+
16
+        //return null;
9 17
     }
10 18
 
11 19
     public static Integer getIndexOfFirstVowel(String word) {
12
-        return null;
20
+        String vowels = "aeiou";
21
+        String wordLowerCase = word.toLowerCase();
22
+
23
+        for (int i = 0; i < wordLowerCase.length(); i++)
24
+            if(vowels.contains(String.valueOf(wordLowerCase.charAt(i)))){
25
+                return i;
26
+            }
27
+
28
+            return null;
13 29
     }
14 30
 
15 31
 
16 32
     public static Boolean startsWithVowel(String word) {
17
-        return null;
33
+       Integer firstVowelIndex = getIndexOfFirstVowel(word);
34
+
35
+        System.out.println(firstVowelIndex);
36
+        //for(int i = 0; i < word.length(); i++)
37
+            if(word.charAt(0) == word.charAt(firstVowelIndex))
38
+                return true;
39
+
40
+        return false;
18 41
     }
19 42
 
20 43
     public static Boolean isVowel(Character character) {
21
-        return null;
44
+
45
+        String charStr = character.toString();
46
+
47
+
48
+
49
+
50
+        return startsWithVowel(charStr);
22 51
     }
23 52
 }

+ 21
- 2
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java 查看文件

@@ -13,15 +13,34 @@ public class ArrayUtility<SomeType> {
13 13
     }
14 14
 
15 15
     public SomeType findOddOccurringValue() {
16
-        return null;
16
+
17
+        for(SomeType type : array)
18
+            if(getNumberOfOccurrences(type) % 2 != 0)
19
+      return type;
20
+
21
+            return null;
22
+
17 23
     }
18 24
 
19 25
     public SomeType findEvenOccurringValue() {
26
+
27
+        for(SomeType type : array)
28
+            if(getNumberOfOccurrences(type) % 2 == 0)
29
+                return type;
30
+
31
+
32
+
20 33
         return null;
21 34
     }
22 35
 
23 36
     public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
24
-        return null;
37
+        Integer counter = 0;
38
+
39
+        for( SomeType type : array )
40
+            if(type.equals(valueToEvaluate))
41
+
42
+                counter++;
43
+        return counter;
25 44
     }
26 45
 
27 46
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {

+ 1
- 1
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/LabStatus.java 查看文件

@@ -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,INCOMPLETE,PENDING;
8 8
 }

+ 7
- 3
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/RockPaperScissorHandSign.java 查看文件

@@ -4,13 +4,17 @@ 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
+    PAPER,ROCK, SCISSOR;
8
+
9
+    RockPaperScissorHandSign() {
10
+    }
8 11
 
9 12
     public RockPaperScissorHandSign getWinner() {
10
-        return null;
13
+
14
+        return SCISSOR;
11 15
     }
12 16
 
13 17
     public RockPaperScissorHandSign getLoser() {
14
-        return null;
18
+        return ROCK;
15 19
     }
16 20
 }

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/arrays/wavegenerator/WaveTest.java 查看文件

@@ -19,7 +19,7 @@ public class WaveTest {
19 19
                 "aaaAaaa",
20 20
                 "aaaaAaa",
21 21
                 "aaaaaAa",
22
-                "aaaaaaA"};
22
+                "aaaaaaAsimulate "};
23 23
 
24 24
         // when
25 25
         String[] actual = WaveGenerator.wave(input);

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/PaperTest.java 查看文件

@@ -25,7 +25,7 @@ public class PaperTest {
25 25
 
26 26
     @Test
27 27
     public void testGetWinner() {
28
-        RockPaperScissorHandSign loser = RockPaperScissorHandSign.valueOf("SCISSORS");
28
+        RockPaperScissorHandSign loser = RockPaperScissorHandSign.valueOf("SCISSOR");
29 29
         Assert.assertEquals(loser, sign.getWinner());
30 30
     }
31 31
 }

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/RockTest.java 查看文件

@@ -20,7 +20,7 @@ public class RockTest {
20 20
 
21 21
     @Test
22 22
     public void testGetLoser() {
23
-        RockPaperScissorHandSign loser = RockPaperScissorHandSign.valueOf("SCISSORS");
23
+        RockPaperScissorHandSign loser = RockPaperScissorHandSign.valueOf("SCISSOR");
24 24
         Assert.assertEquals(loser, sign.getLoser());
25 25
     }
26 26
 

+ 2
- 1
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/ScissorTest.java 查看文件

@@ -1,6 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.objectorientation.enums.rockpaperscissors;
2 2
 
3 3
 import org.junit.Assert;
4
+import org.junit.Before;
4 5
 import org.junit.Test;
5 6
 import rocks.zipcode.io.quiz3.objectorientation.enums.RockPaperScissorHandSign;
6 7
 
@@ -10,7 +11,7 @@ import rocks.zipcode.io.quiz3.objectorientation.enums.RockPaperScissorHandSign;
10 11
 public class ScissorTest {
11 12
     private RockPaperScissorHandSign sign;
12 13
 
13
-    @Test
14
+    @Before
14 15
     public void setup() {
15 16
         // given
16 17
         this.sign = RockPaperScissorHandSign.valueOf("SCISSOR");