Jennifer Chao 6 anos atrás
pai
commit
064e1d0403

+ 11
- 22
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java Ver arquivo

@@ -1,41 +1,30 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3 3
 import java.lang.reflect.Array;
4
+import java.util.ArrayList;
4 5
 import java.util.Arrays;
6
+import java.util.List;
5 7
 
6 8
 /**
7 9
  * @author leon on 09/12/2018.
8 10
  */
9 11
 public class WaveGenerator {
10 12
     public static String[] wave(String str) {
11
-        String[] wave = new String[str.length()];
12
-        Arrays.fill(wave, str.toLowerCase());
13
+        List<String> wave = new ArrayList<>();
14
+        // String[] wave = new String[str.length()];
15
+        // Arrays.fill(wave, str.toLowerCase());
13 16
         int index = 0;
14 17
 
15
-        for (int i = 0; i < wave.length; i++) {
16
-            String[] theword = wave[i].split("");
18
+        for (int i = 0; i < str.length(); i++) {
19
+            String[] theword = str.toLowerCase().split("");
17 20
 
18
-            if (theword[index] != "\\w") {
21
+            if (theword[index].matches("^[a-zA-Z]*$")) {
19 22
                 theword[index] = theword[index].toUpperCase();
20
-                index++;
21
-            }
22
-
23
-            wave[i] = String.join("", theword);
24
-        }
25
-
26
-        return wave;
27
-    }
28
-
29
-    public int countNonAlpha(String str) {
30
-        String[] word = str.split("");
31
-        int nonAlpha = 0;
32
-
33
-        for (String character : word) {
34
-            if (character.equals(" ") || character.equals("_")) {
35
-                nonAlpha++;
23
+                wave.add(String.join("", theword));
36 24
             }
25
+            index++;
37 26
         }
38 27
 
39
-        return nonAlpha;
28
+        return wave.toArray(new String[0]);
40 29
     }
41 30
 }

+ 8
- 6
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java Ver arquivo

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.collections;
2 2
 
3
+import rocks.zipcode.io.quiz3.objectorientation.enums.LabStatus;
4
+
3 5
 /**
4 6
  * @author leon on 10/12/2018.
5 7
  */
@@ -15,12 +17,12 @@ public class Lab {
15 17
         this.labName = labName;
16 18
     }
17 19
 
18
-    public String getLabStatus() {
19
-        return null;
20
-    }
21
-
22
-    public void setLabStatus(String labStatus) {
23
-    }
20
+//    public String getLabStatus() {
21
+//        return null;
22
+//    }
23
+//
24
+//    public void setLabStatus(String labStatus) {
25
+//    }
24 26
 
25 27
     public String getName() {
26 28
         return labName;

+ 19
- 9
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java Ver arquivo

@@ -2,8 +2,7 @@ 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.Map;
5
+import java.util.*;
7 6
 
8 7
 /**
9 8
  * @author leon on 10/12/2018.
@@ -28,7 +27,6 @@ public class Student {
28 27
         }
29 28
     }
30 29
 
31
-
32 30
     public void forkLab(Lab lab) {
33 31
         map.put(lab, LabStatus.PENDING);
34 32
     }
@@ -41,16 +39,28 @@ public class Student {
41 39
         }
42 40
 
43 41
         return null;
44
-
45
-        // throw new UnsupportedOperationException("Method not yet implemented");
46 42
     }
47 43
 
48
-    public String toString(){
49
-        String result = "";
44
+    // treemap wouldnt work for me so i made my own sorting method!!! ヽ༼ ಠ益ಠ ༽ノ
45
+    public String toString() {
46
+        List<String> result = new ArrayList<>();
47
+
50 48
         for (Lab lab : map.keySet()) {
51
-            result += lab.getName() + " > " + map.get(lab) + "\n";
49
+            if (result.size() == 0) {
50
+                result.add(lab.getName() + " > " + map.get(lab) + "\n");
51
+            } else if (lab.getName().charAt(0) > result.get(0).charAt(0)) {
52
+                result.add(lab.getName() + " > " + map.get(lab) + "\n");
53
+            } else {
54
+                result.add(0, lab.getName() + " > " + map.get(lab) + "\n");
55
+            }
56
+        }
57
+
58
+        String foo = "";
59
+
60
+        for (String string : result) {
61
+            foo += string;
52 62
         }
53 63
 
54
-        return result.trim();
64
+        return foo.trim();
55 65
     }
56 66
 }

+ 20
- 1
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java Ver arquivo

@@ -5,6 +5,25 @@ package rocks.zipcode.io.quiz3.fundamentals;
5 5
  */
6 6
 public class PigLatinGenerator {
7 7
     public String translate(String str) {
8
-        return null;
8
+        String[] allWords = str.split(" ");
9
+
10
+        for (int i = 0; i < allWords.length; i++) {
11
+            if (!VowelUtils.hasVowels(str)) {
12
+              allWords[i] = allWords[i] + "ay";
13
+            } else if (VowelUtils.startsWithVowel(allWords[i])) {
14
+                allWords[i] = allWords[i] + "way";
15
+            } else {
16
+                int firstVowelIndex = VowelUtils.getIndexOfFirstVowel(allWords[i]);
17
+                allWords[i] = allWords[i].substring(firstVowelIndex) + allWords[i].substring(0, firstVowelIndex) + "ay";
18
+            }
19
+        }
20
+
21
+        String translated = "";
22
+
23
+        for (String word : allWords) {
24
+            translated += word + " ";
25
+        }
26
+
27
+        return translated.trim();
9 28
     }
10 29
 }

+ 18
- 2
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/RockPaperScissorHandSign.java Ver arquivo

@@ -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("ROCK"),
8
+    PAPER("PAPER"),
9
+    SCISSORS("SCISSORS");
10
+
11
+    private String value;
12
+
13
+    private RockPaperScissorHandSign(String value){
14
+        this.value = value;
15
+    }
8 16
 
9 17
     public RockPaperScissorHandSign getWinner() {
18
+        if (value.equals("ROCK")) {
19
+            return PAPER;
20
+        } else if (value.equals("PAPER")) {
21
+            return SCISSORS;
22
+        } else if (value.equals("SCISSORS")) {
23
+            return ROCK;
24
+        }
25
+
10 26
         return null;
11 27
     }
12 28
 
13 29
     public RockPaperScissorHandSign getLoser() {
14
-        return null;
30
+        return getWinner().getWinner();
15 31
     }
16 32
 }

+ 3
- 2
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/ScissorTest.java Ver arquivo

@@ -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,10 +11,10 @@ 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
-        this.sign = RockPaperScissorHandSign.valueOf("SCISSOR");
17
+        this.sign = RockPaperScissorHandSign.valueOf("SCISSORS");
17 18
     }
18 19
 
19 20