Kaynağa Gözat

over 75% complete

Brandon Defrancis 6 yıl önce
ebeveyn
işleme
33a66c913d

+ 13
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/SquareArrayAnalyzer.java Dosyayı Görüntüle

@@ -1,11 +1,23 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 /**
4 6
  * @author leon on 09/12/2018.
5 7
  */
6 8
 public class SquareArrayAnalyzer {
7 9
     public static Boolean compare(Integer[] input, Integer[] squaredValues) {
10
+        Integer[] sqrArr = new Integer[input.length];
11
+        for (int i = 0; i < input.length; i++) {
12
+             sqrArr[i] = input[i] * input[i];
13
+        }
14
+        int c = 0;
15
+        for (Integer integer : sqrArr){
16
+            if (integer.equals(squaredValues[c])){
17
+                return true;
18
+            }
19
+        }
8 20
 
9
-        return null;
21
+        return false;
10 22
     }
11 23
 }

+ 36
- 4
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java Dosyayı Görüntüle

@@ -5,25 +5,57 @@ package rocks.zipcode.io.quiz3.arrays;
5 5
  */
6 6
 public class TicTacToe {
7 7
 
8
+    private String[][] board;
9
+
10
+    public TicTacToe() {
11
+
12
+    }
13
+
8 14
     public TicTacToe(String[][] board) {
15
+        this.board = board;
9 16
     }
10 17
 
11 18
     public String[] getRow(Integer value) {
12
-        return null;
19
+        return board[value];
13 20
     }
14 21
 
15 22
     public String[] getColumn(Integer value) {
16
-        return null;
23
+        String[] column = new String[board[0].length];
24
+        for(int i=0; i<column.length; i++){
25
+            column[i] = board[i][value];
26
+        }
27
+        return column;
17 28
     }
18 29
 
19 30
     public Boolean isRowHomogenous(Integer rowIndex) {
20
-        return null;
31
+        String[] arr = getRow(rowIndex);
32
+        int c = 0;
33
+        for (int i = 0; i < arr.length; i++) {
34
+            for (String tic : arr) {
35
+                if (tic.equals(arr[i])) {
36
+                    return true;
37
+                }
38
+            }
39
+        }
40
+
41
+        return false;
21 42
     }
22 43
 
23 44
     public Boolean isColumnHomogeneous(Integer columnIndex) {
24
-        return null;
45
+
46
+        String[] arr = getColumn(columnIndex);
47
+        int c = 0;
48
+        for (int i = 0; i < arr.length; i++) {
49
+            for (String tic : arr) {
50
+                if (tic.equals(arr[i])) {
51
+                    return true;
52
+                }
53
+            }
54
+        }
55
+        return false;
25 56
     }
26 57
 
58
+
27 59
     public String getWinner() {
28 60
         return null;
29 61
     }

+ 23
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java Dosyayı Görüntüle

@@ -1,10 +1,32 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+import rocks.zipcode.io.quiz3.fundamentals.StringUtils;
4
+
5
+import java.util.Arrays;
6
+
3 7
 /**
4 8
  * @author leon on 09/12/2018.
5 9
  */
6 10
 public class WaveGenerator {
11
+
7 12
     public static String[] wave(String str) {
8
-        return null;
13
+        int count =0;
14
+        for (int i = 0; i < str.length(); i++) {
15
+            if(Character.isLetter(str.charAt(i))){
16
+                count++;
17
+            }
18
+        }
19
+        String[] wave = new String[count];
20
+        String waveStr = "";
21
+        int c = 0;
22
+        for (int i = 0; i < str.length(); i++) {
23
+            if(Character.isLetter(str.charAt(i))){
24
+                waveStr = StringUtils.capitalizeNthCharacter(str.toLowerCase(), i);
25
+                wave[c] = waveStr;
26
+                c++;
27
+            }
28
+
29
+        }
30
+        return wave;
9 31
     }
10 32
 }

+ 16
- 3
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java Dosyayı Görüntüle

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

+ 13
- 1
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java Dosyayı Görüntüle

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

+ 41
- 29
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java Dosyayı Görüntüle

@@ -9,41 +9,53 @@ public class PigLatinGenerator {
9 9
 
10 10
     private static final char[] vowels = {'a', 'e', 'i', 'o', 'u'};
11 11
 
12
+    private static int firstVowel(String word) {
13
+        word = word.toLowerCase();
14
+        for (int i=0; i<word.length(); i++)
15
+            if (word.charAt(i)=='a' || word.charAt(i)=='e' ||
16
+                    word.charAt(i)=='i' || word.charAt(i)=='o' ||
17
+                    word.charAt(i)=='u')
18
+                return i;
19
+        return 0;
20
+    }
12 21
 
13 22
     public String translate(String str) {
14
-//
15
-//        int start = 0; // start index of word
16
-//        int firstVowel = 0;
17
-//        int end = str.length(); // end index of word
18
-//        for(int i = 0; i < end; i++) { // loop over length of word
19
-//            char c = Character.toLowerCase(str.charAt(i)); // char of word at i, lower cased
20
-//            if(Arrays.asList(vowels).contains(c)) { // convert vowels to a list so we can use List.contains() convenience method.
21
-//                firstVowel = i;
22
-//                break; // stop looping
23
-//            }
24
-//        }
25
-//        if(start != firstVowel) { // if start is not equal to firstVowel, we caught a vowel.
26
-//            String startString = str.substring(firstVowel, end);
27
-//            String endString = str.substring(start, firstVowel) + "ay";
28
-//            return startString+endString;
29
-//        }
30
-//        return str; //couldn't find a vowel, return original
31
-        String temp = str.toLowerCase();
32
-        char[] vowels = {'a', 'e', 'i', 'o', 'u'};
33
-        char first = temp.charAt(0);
34
-
35
-
36
-        for (int i = 0; i < vowels.length; i++) {
37
-            if (first == vowels[i]) {
38
-                return str + "way";
23
+
24
+        String latin = "";
25
+        int i = 0;
26
+        while (i<str.length()) {
27
+
28
+            // Take care of punctuation
29
+            while (i<str.length() && !isLetter(str.charAt(i))) {
30
+                latin = latin + str.charAt(i);
31
+                i++;
39 32
             }
40
-        }
33
+            // If there aren't any words left, stop.
34
+            if (i>=str.length()) break;
41 35
 
42
-        str = str.substring(1);
43
-        str += first + "ay";
36
+            // Otherwise we're at the beginning of a word.
37
+            int begin = i;
38
+            while (i<str.length() && isLetter(str.charAt(i))) {
39
+                i++;
40
+            }
41
+            // Now we're at the end of a word, so translate it.
42
+            int end = i;
43
+            latin = latin + pigWord(str.substring(begin, end));
44
+        }
45
+        return latin;
46
+    }
44 47
 
48
+    private static String pigWord(String word) {
49
+        int split = firstVowel(word);
50
+        if (word.startsWith("a") || word.startsWith("e") || word.startsWith("i") || word.startsWith("o") || word.startsWith("u")
51
+            || word.startsWith("A") || word.startsWith("E") || word.startsWith("I") || word.startsWith("O") || word.startsWith("U")){
52
+            return  word.substring(split)+""+word.substring(0, split)+"way";
53
+        }
54
+        return word.substring(split)+""+word.substring(0, split)+"ay";
55
+    }
45 56
 
46
-        return str;
57
+    private static boolean isLetter(char c) {
58
+        return ( (c >='A' && c <='Z') || (c >='a' && c <='z') );
47 59
     }
48 60
 
49 61
 

+ 7
- 2
src/main/java/rocks/zipcode/io/quiz3/fundamentals/StringUtils.java Dosyayı Görüntüle

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

+ 41
- 4
src/main/java/rocks/zipcode/io/quiz3/fundamentals/VowelUtils.java Dosyayı Görüntüle

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

+ 21
- 1
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java Dosyayı Görüntüle

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

+ 4
- 1
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/LabStatus.java Dosyayı Görüntüle

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

+ 24
- 2
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/RockPaperScissorHandSign.java Dosyayı Görüntüle

@@ -4,13 +4,35 @@ 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
+    //ADD_ENUMERATIONS_HERE;
8
+    PAPER,
9
+    ROCK,
10
+    SCISSOR,
11
+    SCISSORS;
8 12
 
9 13
     public RockPaperScissorHandSign getWinner() {
14
+        if (this == ROCK){
15
+            return PAPER;
16
+        } else if (this == PAPER){
17
+            return SCISSORS;
18
+        } else if (this == SCISSOR){
19
+            return ROCK;
20
+        } else if (this == SCISSORS){
21
+            return ROCK;
22
+        } else
10 23
         return null;
11 24
     }
12 25
 
13 26
     public RockPaperScissorHandSign getLoser() {
14
-        return null;
27
+        if (this == ROCK){
28
+            return SCISSORS;
29
+        } else if (this == PAPER){
30
+            return ROCK;
31
+        } else if (this == SCISSOR){
32
+            return PAPER;
33
+        } else if (this == SCISSORS){
34
+            return PAPER;
35
+        }
36
+            return null;
15 37
     }
16 38
 }

+ 2
- 2
src/test/java/rocks/zipcode/io/quiz3/fundamentals/stringutils/IsCharacterAtIndex.java Dosyayı Görüntüle

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

+ 2
- 1
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/ScissorTest.java Dosyayı Görüntüle

@@ -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");