#33 Steffon Williams

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

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

5
  */
5
  */
6
 public class SquareArrayAnalyzer {
6
 public class SquareArrayAnalyzer {
7
     public static Boolean compare(Integer[] input, Integer[] squaredValues) {
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 View File

1
 package rocks.zipcode.io.quiz3.arrays;
1
 package rocks.zipcode.io.quiz3.arrays;
2
 
2
 
3
+import java.util.stream.IntStream;
4
+
3
 /**
5
 /**
4
  * @author leon on 09/12/2018.
6
  * @author leon on 09/12/2018.
5
  */
7
  */
6
 public class TicTacToe {
8
 public class TicTacToe {
7
 
9
 
10
+    String[][] board;
11
+
8
     public TicTacToe(String[][] board) {
12
     public TicTacToe(String[][] board) {
13
+        this.board = board;
14
+
9
     }
15
     }
10
 
16
 
11
     public String[] getRow(Integer value) {
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
     public String[] getColumn(Integer value) {
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
     public Boolean isRowHomogenous(Integer rowIndex) {
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
     public Boolean isColumnHomogeneous(Integer columnIndex) {
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
     public String getWinner() {
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 View File

1
 package rocks.zipcode.io.quiz3.arrays;
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
  * @author leon on 09/12/2018.
8
  * @author leon on 09/12/2018.
5
  */
9
  */
6
 public class WaveGenerator {
10
 public class WaveGenerator {
7
     public static String[] wave(String str) {
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
         return null;
20
         return null;
9
     }
21
     }
10
 }
22
 }

+ 13
- 2
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java View File

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

5
  */
5
  */
6
 public class PigLatinGenerator {
6
 public class PigLatinGenerator {
7
     public String translate(String str) {
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 View File

5
  */
5
  */
6
 public class StringUtils {
6
 public class StringUtils {
7
     public static String capitalizeNthCharacter(String str, Integer indexToCapitalize) {
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
     public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
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 View File

5
  */
5
  */
6
 public class VowelUtils {
6
 public class VowelUtils {
7
     public static Boolean hasVowels(String word) {
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
     public static Integer getIndexOfFirstVowel(String word) {
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
     public static Boolean startsWithVowel(String word) {
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
     public static Boolean isVowel(Character character) {
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 View File

13
     }
13
     }
14
 
14
 
15
     public SomeType findOddOccurringValue() {
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
     public SomeType findEvenOccurringValue() {
25
     public SomeType findEvenOccurringValue() {
26
+
27
+        for(SomeType type : array)
28
+            if(getNumberOfOccurrences(type) % 2 == 0)
29
+                return type;
30
+
31
+
32
+
20
         return null;
33
         return null;
21
     }
34
     }
22
 
35
 
23
     public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
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
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {
46
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {

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

4
  * @author leon on 10/12/2018.
4
  * @author leon on 10/12/2018.
5
  */
5
  */
6
 public enum LabStatus {
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 View File

4
  * @author leon on 09/12/2018.
4
  * @author leon on 09/12/2018.
5
  */
5
  */
6
 public enum RockPaperScissorHandSign {
6
 public enum RockPaperScissorHandSign {
7
-    ADD_ENUMERATIONS_HERE;
7
+    PAPER,ROCK, SCISSOR;
8
+
9
+    RockPaperScissorHandSign() {
10
+    }
8
 
11
 
9
     public RockPaperScissorHandSign getWinner() {
12
     public RockPaperScissorHandSign getWinner() {
10
-        return null;
13
+
14
+        return SCISSOR;
11
     }
15
     }
12
 
16
 
13
     public RockPaperScissorHandSign getLoser() {
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 View File

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

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/PaperTest.java View File

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

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/RockTest.java View File

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

+ 2
- 1
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/ScissorTest.java View File

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