Parcourir la source

Curtis Cook's Quiz3

curtiscook il y a 5 ans
Parent
révision
864c358ff6

+ 5
- 4
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java Voir le fichier

@@ -7,11 +7,12 @@ public class WaveGenerator {
7 7
     public static String[] wave(String str) {
8 8
         String[] strWave = new String[str.length()];
9 9
         for (int i = 0; i < strWave.length; i++) {
10
-            String updatedStr = str.substring(i + 1);
11
-            strWave[i] = updatedStr;
10
+            if (Character.isUpperCase(str.charAt(i))) {
11
+                strWave[0] = Character.toLowerCase(str.charAt(i)) + str.substring(i + 1);
12
+            } else {
13
+                strWave[0] = Character.toUpperCase(str.charAt(i)) + str.substring(i + 1);
14
+            }
12 15
         }
13 16
         return strWave;
14 17
     }
15
-
16
-
17 18
 }

+ 2
- 2
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java Voir le fichier

@@ -4,8 +4,8 @@ package rocks.zipcode.io.quiz3.collections;
4 4
  * @author leon on 10/12/2018.
5 5
  */
6 6
 public class Lab {
7
-    private String labStatus;
8 7
     private String labName;
8
+    private String labStatus;
9 9
 
10 10
     public Lab() {
11 11
         this(null);
@@ -26,4 +26,4 @@ public class Lab {
26 26
     public String getName() {
27 27
         return labName;
28 28
     }
29
-}
29
+}

+ 5
- 4
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java Voir le fichier

@@ -9,6 +9,7 @@ import java.util.Map;
9 9
  */
10 10
 public class Student {
11 11
     private Lab lab;
12
+    private LabStatus labStatus;
12 13
 
13 14
     public Student() {
14 15
         this(null);
@@ -18,15 +19,15 @@ public class Student {
18 19
     }
19 20
 
20 21
     public void setLabStatus(Lab lab, LabStatus labStatus) {
21
-//        lab.setLabStatus(labStatus);
22
+        lab.setLabStatus(labStatus.toString());
22 23
     }
23 24
 
24 25
 
25 26
     public void forkLab(Lab lab) {
26
-        lab.setLabStatus("PENDING");
27 27
     }
28 28
 
29 29
     public LabStatus getLabStatus(String labName) {
30
-        throw new UnsupportedOperationException("Method not yet implemented");
30
+//        throw new UnsupportedOperationException("Method not yet implemented");
31
+        return LabStatus.valueOf(labName);
31 32
     }
32
-}
33
+}

+ 15
- 1
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java Voir le fichier

@@ -5,6 +5,20 @@ package rocks.zipcode.io.quiz3.fundamentals;
5 5
  */
6 6
 public class PigLatinGenerator {
7 7
     public String translate(String str) {
8
-        return null;
8
+        StringBuilder sb = new StringBuilder();
9
+        String[] stringSplit = str.split(" ");
10
+        for (String word : stringSplit) {
11
+            if (VowelUtils.startsWithVowel(word)) {
12
+                sb.append(word += "way ");
13
+            } else {
14
+                Integer index = VowelUtils.getIndexOfFirstVowel(word);
15
+                if (index == null) {
16
+                    sb.append(word + "ay ");
17
+                } else {
18
+                    sb.append(word.substring(index) + word.substring(0, index) + "ay ");
19
+                }
20
+            }
21
+        }
22
+        return sb.toString().trim();
9 23
     }
10 24
 }

+ 14
- 2
src/main/java/rocks/zipcode/io/quiz3/fundamentals/StringUtils.java Voir le fichier

@@ -5,10 +5,22 @@ 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;
8
+        StringBuilder sb = new StringBuilder(str.length());
9
+        String letter = String.valueOf(str.charAt(indexToCapitalize)).toUpperCase();
10
+        for (int i = 0; i < str.length(); i++) {
11
+            if (i != indexToCapitalize) {
12
+                sb.append(str.charAt(i));
13
+            } else {
14
+                sb.append(letter);
15
+            }
16
+        }
17
+        return sb.toString();
9 18
     }
10 19
 
11 20
     public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
12
-        return null;
21
+        if (baseString.charAt(indexOfString) == characterToCheckFor) {
22
+            return true;
23
+        }
24
+        return false;
13 25
     }
14 26
 }

+ 46
- 3
src/main/java/rocks/zipcode/io/quiz3/fundamentals/VowelUtils.java Voir le fichier

@@ -5,19 +5,62 @@ 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
+        if (word.contains("a") || word.contains("e") ||
9
+                word.contains("i") || word.contains("o") ||
10
+                word.contains("u")) {
11
+            return true;
12
+        }
13
+        return false;
9 14
     }
10 15
 
11 16
     public static Integer getIndexOfFirstVowel(String word) {
17
+        for (int i = 0; i < word.length(); i++) {
18
+            if (word.charAt(i) == 'a' ||
19
+                    word.charAt(i) == 'A' ||
20
+                    word.charAt(i) == 'e' ||
21
+                    word.charAt(i) == 'E' ||
22
+                    word.charAt(i) == 'i' ||
23
+                    word.charAt(i) == 'I' ||
24
+                    word.charAt(i) == 'o' ||
25
+                    word.charAt(i) == 'O' ||
26
+                    word.charAt(i) == 'u' ||
27
+                    word.charAt(i) == 'U') {
28
+                return i;
29
+            }
30
+        }
12 31
         return null;
13 32
     }
14 33
 
15 34
 
16 35
     public static Boolean startsWithVowel(String word) {
17
-        return null;
36
+        if (word.startsWith("A") ||
37
+                word.startsWith("a") ||
38
+                word.startsWith("E") ||
39
+                word.startsWith("e") ||
40
+                word.startsWith("I") ||
41
+                word.startsWith("i") ||
42
+                word.startsWith("O") ||
43
+                word.startsWith("o") ||
44
+                word.startsWith("U") ||
45
+                word.startsWith("u")) {
46
+            return true;
47
+        }
48
+        return false;
18 49
     }
19 50
 
20 51
     public static Boolean isVowel(Character character) {
21
-        return null;
52
+        if (character == 'a' ||
53
+                character == 'A' ||
54
+                character == 'e' ||
55
+                character == 'E' ||
56
+                character == 'i' ||
57
+                character == 'I' ||
58
+                character == 'o' ||
59
+                character == 'O' ||
60
+                character == 'u' ||
61
+                character == 'U') {
62
+            return true;
63
+        }
64
+        return false;
22 65
     }
23 66
 }

+ 17
- 1
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/RockPaperScissorHandSign.java Voir le fichier

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

+ 2
- 2
src/test/java/rocks/zipcode/io/quiz3/fundamentals/stringutils/IsCharacterAtIndex.java Voir le fichier

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