Jose Bedolla 5 лет назад
Родитель
Сommit
efbbc2758b

+ 26
- 4
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java Просмотреть файл

@@ -18,19 +18,41 @@ public class TicTacToe {
18 18
 
19 19
     public String[] getColumn(Integer value) {
20 20
         String[] singleArr = new String[board.length];
21
-
21
+        for (int i = 0; i <board.length ; i++) {
22
+            singleArr[i] = board[i][value];
23
+        }
22 24
         return singleArr;
23 25
     }
24 26
 
25 27
     public Boolean isRowHomogenous(Integer rowIndex) {
26
-        return null;
28
+        String[] row = board[rowIndex];
29
+        for (int i = 0; i <row.length; i++) {
30
+            if (row[i]==row[row.length-1-i]){
31
+                return true;
32
+            }
33
+        }
34
+       return false;
27 35
     }
28 36
 
29 37
     public Boolean isColumnHomogeneous(Integer columnIndex) {
30
-        return null;
38
+        for(int i = 0; i < board.length; i++){
39
+            for(int j = 1; j < board[i].length; j++){
40
+                if(!board[i][columnIndex].equals(board[i][j])){
41
+                    return true;
42
+                }
43
+            }
44
+        }
45
+        return false;
31 46
     }
32 47
 
33 48
     public String getWinner() {
34
-        return null;
49
+        for (int i = 0; i <board.length ; i++) {
50
+            for (int j = 0; j <board.length ; j++) {
51
+                if (board[i][j] == "X"){
52
+                    return "X";
53
+                }
54
+            }
55
+        }
56
+        return "O";
35 57
     }
36 58
 }

+ 6
- 2
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java Просмотреть файл

@@ -5,6 +5,10 @@ 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[] arr = new String[str.length()];
9
+        
10
+        return arr;
9 11
     }
10
-}
12
+    }
13
+
14
+

+ 10
- 4
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java Просмотреть файл

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

+ 10
- 1
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java Просмотреть файл

@@ -2,20 +2,29 @@ package rocks.zipcode.io.quiz3.collections;
2 2
 
3 3
 import rocks.zipcode.io.quiz3.objectorientation.enums.LabStatus;
4 4
 
5
+import java.util.Collections;
5 6
 import java.util.Map;
6 7
 
7 8
 /**
8 9
  * @author leon on 10/12/2018.
9 10
  */
10 11
 public class Student {
12
+
13
+    private Lab lab;
14
+    private LabStatus labStatus;
15
+    Map<Lab,LabStatus> map;
16
+
11 17
     public Student() {
12
-        this(null);
18
+        this(Collections.emptyMap());
13 19
     }
14 20
 
15 21
     public Student(Map<Lab, LabStatus> map) {
22
+        this.map = map;
16 23
     }
17 24
 
18 25
     public void setLabStatus(Lab lab, LabStatus labStatus) {
26
+        this.lab=lab;
27
+        this.labStatus=labStatus;
19 28
     }
20 29
 
21 30
 

+ 7
- 2
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java Просмотреть файл

@@ -4,7 +4,12 @@ package rocks.zipcode.io.quiz3.fundamentals;
4 4
  * @author leon on 09/12/2018.
5 5
  */
6 6
 public class PigLatinGenerator {
7
-    public String translate(String str) {
8
-        return null;
7
+
8
+    public String translate(String original) {
9
+        String vowels = "aeiouAEIOU";
10
+        if (vowels.indexOf(original.charAt(0)) >= 0) {
11
+            return original + "way";
12
+        }
13
+        return original.substring(1) + original.charAt(0) + "ay";
9 14
     }
10 15
 }

+ 16
- 3
src/main/java/rocks/zipcode/io/quiz3/fundamentals/StringUtils.java Просмотреть файл

@@ -1,14 +1,27 @@
1 1
 package rocks.zipcode.io.quiz3.fundamentals;
2 2
 
3
+import java.util.stream.Collectors;
4
+import java.util.stream.Stream;
5
+
3 6
 /**
4 7
  * @author leon on 09/12/2018.
5 8
  */
6 9
 public class StringUtils {
7
-    public static String capitalizeNthCharacter(String str, Integer indexToCapitalize) {
8
-        return null;
10
+    public static String capitalizeNthCharacter(String text, Integer index) {
11
+        String a = text.substring(index,index+1);
12
+        String b =a.toUpperCase();
13
+        String o = text.substring(index+1,text.length());
14
+        StringBuilder builder = new StringBuilder();
15
+        builder.append(b);
16
+        builder.append(o);
17
+        return builder.toString();
9 18
     }
10 19
 
11 20
     public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
12
-        return null;
21
+
22
+        if (baseString.charAt(indexOfString) == characterToCheckFor){
23
+            return true;
24
+        }
25
+        return false;
13 26
     }
14 27
 }

+ 49
- 7
src/main/java/rocks/zipcode/io/quiz3/fundamentals/VowelUtils.java Просмотреть файл

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

+ 40
- 1
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java Просмотреть файл

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

+ 4
- 3
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/RockPaperScissorHandSign.java Просмотреть файл

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