Quellcode durchsuchen

30 minutes left

Whitney Martinez vor 6 Jahren
Ursprung
Commit
100760a7d7

+ 16
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/SquareArrayAnalyzer.java Datei anzeigen

@@ -4,7 +4,22 @@ package rocks.zipcode.io.quiz3.arrays;
4 4
  * @author leon on 09/12/2018.
5 5
  s*/
6 6
 public class SquareArrayAnalyzer {
7
+
7 8
     public static Boolean compare(Integer[] input, Integer[] squaredValues) {
8
-        return null;
9
+        Boolean flag = null;
10
+
11
+        for (int i = 0; i <input.length ; i++) {
12
+
13
+            for (int j = 0; j <squaredValues.length ; j++) {
14
+
15
+                if(input[i] == Math.abs(Math.sqrt(squaredValues[j]))){
16
+                        flag = true;
17
+                }else{
18
+                    flag = false;
19
+                }
20
+            }
21
+
22
+        }
23
+        return flag;
9 24
     }
10 25
 }

+ 67
- 7
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java Datei anzeigen

@@ -1,30 +1,90 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match;
4
+import com.sun.org.apache.xpath.internal.operations.Bool;
5
+
6
+import java.util.ArrayList;
7
+import java.util.Arrays;
8
+
3 9
 /**
4 10
  * @author leon on 09/12/2018.
5 11
  */
6 12
 public class TicTacToe {
7 13
 
14
+    private String[][] tictac;
15
+
8 16
     public TicTacToe(String[][] board) {
17
+        this.tictac = board;
9 18
     }
10 19
 
11 20
     public String[] getRow(Integer value) {
12
-        return null;
21
+
22
+        ArrayList<String> rows = new ArrayList<>();
23
+
24
+        for (int i = value; i <= value ; i++) {
25
+
26
+            for (int j = 0; j < tictac.length ; j++) {
27
+               rows.add(tictac[i][j]);
28
+            }
29
+        }
30
+
31
+        String[] rowingArrays = new String[rows.size()];
32
+        rowingArrays = rows.toArray(rowingArrays);
33
+        return rowingArrays;
13 34
     }
14 35
 
15 36
     public String[] getColumn(Integer value) {
16
-        return null;
17
-    }
18 37
 
38
+        String [] arr = new String[tictac.length];
39
+        for (int i = 0; i <= tictac.length-1 ; i++) {
40
+
41
+                arr[i] = tictac[i][value];
42
+
43
+
44
+
45
+        }
46
+        return arr;
47
+    }
48
+        //Homongenous means of the same type;
19 49
     public Boolean isRowHomogenous(Integer rowIndex) {
20
-        return null;
50
+        String [] gettingrow = getRow(rowIndex);
51
+
52
+        Boolean match = Arrays.stream(gettingrow).allMatch(s -> s.equals(gettingrow[0]));
53
+
54
+        return match;
21 55
     }
22 56
 
23 57
     public Boolean isColumnHomogeneous(Integer columnIndex) {
24
-        return null;
58
+
59
+        String [] gettingColumn = getColumn(columnIndex);
60
+
61
+        Boolean match = Arrays.stream(gettingColumn).allMatch(s -> s.equals(gettingColumn[0]));
62
+
63
+        return match;
25 64
     }
26 65
 
27
-    public String getWinner() {
28
-        return null;
66
+    public String getWinner()
67
+    {
68
+        String winner = "";
69
+
70
+        int counter = 0;
71
+        int counting = 0;
72
+
73
+        for (int i = 0; i < tictac.length ; i++) {
74
+            for (int j = 0; j < tictac.length ; j++) {
75
+
76
+                if (tictac[i][j].equals("X")){
77
+                    counter++;
78
+                }else if(tictac[i][j].equals("O")){
79
+                   counting ++;
80
+                }
81
+            }
82
+            if(counter == 3){
83
+                winner = "X";
84
+            }else if(counting == 3){
85
+                winner = "O";
86
+            }
87
+        }
88
+        return winner;
29 89
     }
30 90
 }

+ 20
- 2
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java Datei anzeigen

@@ -5,6 +5,24 @@ package rocks.zipcode.io.quiz3.arrays;
5 5
  */
6 6
 public class WaveGenerator {
7 7
     public static String[] wave(String str) {
8
-        return null;
9
-    }
8
+
9
+        String [] collection = new String[str.length()];
10
+        StringBuilder sb = new StringBuilder();
11
+
12
+
13
+        for (int i = 0; i < str.length() ; i++) {
14
+            for (int j = 0; j <= i; j++) {
15
+                if (i == 0) {
16
+                    collection[i] = str.charAt(0) + str.substring(1).toLowerCase();
17
+
18
+                }else {
19
+                        collection[i] = str.substring(j).toLowerCase() + str.charAt(i) + str.substring(0, j).toLowerCase();
20
+                    }
21
+                }
22
+
23
+
24
+            }
25
+        return collection;
26
+        }
27
+
10 28
 }

+ 8
- 3
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java Datei anzeigen

@@ -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 static String name;
8
+
7 9
     public Lab() {
8
-        this(null);
10
+        this(name);
9 11
     }
10 12
 
11 13
     public Lab(String labName) {
14
+        name =labName;
12 15
     }
13 16
 
14 17
     public String getLabStatus() {
15
-        return null;
18
+
19
+        return name;
16 20
     }
17 21
 
18 22
     public void setLabStatus(String labStatus) {
23
+       name =labStatus;
19 24
     }
20 25
 
21 26
     public String getName() {
22
-        return null;
27
+        return name;
23 28
     }
24 29
 }

+ 21
- 4
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java Datei anzeigen

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

+ 17
- 1
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java Datei anzeigen

@@ -1,10 +1,26 @@
1 1
 package rocks.zipcode.io.quiz3.fundamentals;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 /**
4 6
  * @author leon on 09/12/2018.
5 7
  */
6 8
 public class PigLatinGenerator {
9
+    private static final char[] vowels = {'a','e','i','o','u'};
7 10
     public String translate(String str) {
8
-        return null;
11
+        String newWord = "";
12
+
13
+//       if(str.startsWith("a") || str.startsWith("e") ||str.startsWith("i")
14
+//               ||str.startsWith("o") ||str.startsWith("u")){
15
+//          return newWord = str += "way";
16
+//
17
+//       }else if(!str.startsWith("a")|| !str.startsWith("e") ||!str.startsWith("i")
18
+//               ||!str.startsWith("o") ||!str.startsWith("u")){
19
+//
20
+//            return newWord = str.substring(1) + str.charAt(0)  + "ay";
21
+//       }else{
22
+//           return newWord;
23
+//       }
24
+        
9 25
     }
10 26
 }

+ 21
- 2
src/main/java/rocks/zipcode/io/quiz3/fundamentals/StringUtils.java Datei anzeigen

@@ -1,14 +1,33 @@
1 1
 package rocks.zipcode.io.quiz3.fundamentals;
2 2
 
3
+import java.util.regex.Matcher;
4
+import java.util.regex.Pattern;
5
+
3 6
 /**
4 7
  * @author leon on 09/12/2018.
5 8
  */
6 9
 public class StringUtils {
7 10
     public static String capitalizeNthCharacter(String str, Integer indexToCapitalize) {
8
-        return null;
11
+
12
+       char[] arr = str.toCharArray();
13
+
14
+       arr[indexToCapitalize] = Character.toUpperCase(arr[indexToCapitalize]);
15
+       String str2 = new String(arr);
16
+       return str2;
9 17
     }
10 18
 
11 19
     public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
12
-        return null;
20
+
21
+        Boolean flag;
22
+        if(baseString.length() ==0)
23
+            return false;
24
+
25
+        if(baseString.charAt(indexOfString) == characterToCheckFor){
26
+            flag = true;
27
+        }else{
28
+            flag = false;
29
+        }
30
+
31
+        return flag;
13 32
     }
14 33
 }

+ 38
- 3
src/main/java/rocks/zipcode/io/quiz3/fundamentals/VowelUtils.java Datei anzeigen

@@ -1,23 +1,58 @@
1 1
 package rocks.zipcode.io.quiz3.fundamentals;
2 2
 
3
+import com.sun.org.apache.xpath.internal.operations.Bool;
4
+
3 5
 /**
4 6
  * @author leon on 09/12/2018.
5 7
  */
6 8
 public class VowelUtils {
9
+    private static final char[] vowels = {'a','e','i','o','u','A','E','I','O','U'};
10
+
7 11
     public static Boolean hasVowels(String word) {
8
-        return null;
12
+        return word.matches("[aeiou]");
13
+
9 14
     }
10 15
 
11 16
     public static Integer getIndexOfFirstVowel(String word) {
17
+
18
+        final String vowel = "aeiou";
19
+
20
+        for (int i = 0; i < word.length(); i++) {
21
+            if(vowel.contains(String.valueOf(word.charAt(i))))
22
+            {
23
+                return i;
24
+            }
25
+        }
12 26
         return null;
13 27
     }
14 28
 
15 29
 
16 30
     public static Boolean startsWithVowel(String word) {
17
-        return null;
31
+
32
+        Boolean flag = null;
33
+        String smallword = word.toLowerCase();
34
+
35
+        for (int i = 0; i <vowels.length ; i++) {
36
+            if(smallword.charAt(0) == vowels[i]){
37
+                return true;
38
+            }else{
39
+                flag = false;
40
+            }
41
+        }
42
+        return flag;
18 43
     }
19 44
 
20 45
     public static Boolean isVowel(Character character) {
21
-        return null;
46
+
47
+        Boolean flag = null;
48
+
49
+        for (int i = 0; i <vowels.length ; i++) {
50
+            if(character == vowels[i]){
51
+                return true;
52
+            }else{
53
+                flag = false;
54
+            }
55
+        }
56
+        return flag;
22 57
     }
23 58
 }

+ 44
- 3
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java Datei anzeigen

@@ -1,5 +1,9 @@
1 1
 package rocks.zipcode.io.quiz3.generics;
2 2
 
3
+import java.lang.reflect.Array;
4
+import java.util.ArrayList;
5
+import java.util.Arrays;
6
+import java.util.List;
3 7
 import java.util.function.Function;
4 8
 
5 9
 /**
@@ -9,22 +13,59 @@ public class ArrayUtility<SomeType> {
9 13
     private final SomeType[] array;
10 14
 
11 15
     public ArrayUtility(SomeType[] array) {
16
+
12 17
         this.array = array;
13 18
     }
14 19
 
15 20
     public SomeType findOddOccurringValue() {
16
-        return null;
21
+
22
+        for (int i = 0; i < array.length ; i++) {
23
+
24
+            int count =0;
25
+            for (int j = 0; j < array.length; j++) {
26
+                if(array[i] == array[j])
27
+                    count ++;
28
+            }
29
+            if(count % 2 !=0){
30
+                return array[i];
31
+            }
32
+
33
+        }
34
+            return null;
17 35
     }
18 36
 
19 37
     public SomeType findEvenOccurringValue() {
38
+        for (int i = 0; i < array.length ; i++) {
39
+
40
+            int count =0;
41
+            for (int j = 0; j < array.length; j++) {
42
+                if(array[i] == array[j])
43
+                    count ++;
44
+            }
45
+            if(count % 2 ==0){
46
+                return array[i];
47
+            }
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
+
56
+        for (int i = 0; i < array.length ; i++) {
57
+
58
+            if(array[i] == valueToEvaluate) count ++;
59
+
60
+        }
61
+        return  count;
25 62
     }
26 63
 
27 64
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {
28
-        return null;
65
+
66
+       return null;
67
+
68
+
69
+
29 70
     }
30 71
 }

+ 3
- 1
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/LabStatus.java Datei anzeigen

@@ -4,5 +4,7 @@ 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,
8
+               INCOMPLETE,
9
+               PENDING;
8 10
 }

+ 11
- 3
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/RockPaperScissorHandSign.java Datei anzeigen

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

+ 2
- 2
src/test/java/rocks/zipcode/io/quiz3/fundamentals/stringutils/IsCharacterAtIndex.java Datei anzeigen

@@ -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