mpierse 6 лет назад
Родитель
Сommit
9abcd80c81

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

@@ -4,20 +4,45 @@ 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;
7
+    public static Boolean hasVowels(String str) {
8
+
9
+        for (int i = 0; i < str.length() ; i++) {
10
+            if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i'
11
+                    || str.charAt(i) == 'o' || str.charAt(i) == 'u' || str.charAt(i) == 'A' ||
12
+                    str.charAt(i) == 'E' || str.charAt(i) == 'I' || str.charAt(i) == 'O'
13
+                    || str.charAt(i) == 'U')
14
+                return true;
15
+        }
16
+        return false;
9 17
     }
10 18
 
11
-    public static Integer getIndexOfFirstVowel(String word) {
19
+    public static Integer getIndexOfFirstVowel(String str) {
20
+
21
+        for (int i = 0; i < str.length() ; i++) {
22
+            if (str.charAt(i) == 'a'  || str.charAt(i) == 'e' || str.charAt(i) == 'i'
23
+                    || str.charAt(i) =='o' || str.charAt(i) == 'u' || str.charAt(i) == 'A' ||
24
+                    str.charAt(i) == 'E' || str.charAt(i) == 'I' || str.charAt(i) == 'O'
25
+                    || str.charAt(i) == 'U')
26
+               return  i;
27
+        }
12 28
         return null;
13 29
     }
14 30
 
15 31
 
16
-    public static Boolean startsWithVowel(String word) {
17
-        return null;
32
+    public static Boolean startsWithVowel(String str) {
33
+        return  (str.startsWith("a")||str.startsWith("e")||str.startsWith("i")||
34
+                str.startsWith("o")||str.startsWith("u")||str.startsWith("A")||
35
+                str.startsWith("E")||str.startsWith("I")||str.startsWith("O")||str.startsWith("U"));
18 36
     }
19 37
 
20 38
     public static Boolean isVowel(Character character) {
21
-        return null;
39
+        if (character == 'a'  || character == 'e' || character == 'i'
40
+                || character =='o' || character == 'u' ||character == 'A' ||
41
+                character == 'E' || character == 'I' || character == 'O'
42
+                || character == 'U')
43
+            return  true;
44
+        return false;
45
+    }
46
+
22 47
     }
23
-}
48
+

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

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

+ 3
- 2
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/ScissorTest.java Просмотреть файл

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