Christian Sheridan 5 anos atrás
pai
commit
360ae69f6b

+ 1
- 0
src/main/java/rocks/zipcode/quiz5/collections/Food.java Ver arquivo

@@ -9,6 +9,7 @@ import java.util.Map;
9 9
  * @author leon on 27/12/2018.
10 10
  */
11 11
 public class Food {
12
+
12 13
     public List<Spice> getAllSpices() {
13 14
         return null;
14 15
     }

+ 20
- 1
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java Ver arquivo

@@ -1,12 +1,31 @@
1 1
 package rocks.zipcode.quiz5.collections;
2 2
 
3
+import java.util.HashMap;
3 4
 import java.util.Map;
4 5
 
5 6
 public class WordCounter {
7
+
8
+    String[] strings;
9
+
6 10
     public WordCounter(String... strings) {
11
+        this.strings = strings;
12
+    }
13
+
14
+    public Integer wordCount(String word){
15
+        Integer counter = 0;
16
+        for(String s: strings){
17
+            if(s.equals(word)){
18
+                counter++;
19
+            }
20
+        }
21
+        return counter;
7 22
     }
8 23
 
9 24
     public Map<String, Integer> getWordCountMap() {
10
-        return null;
25
+        Map<String, Integer> wordCountMap = new HashMap<>();
26
+        for (String s: strings) {
27
+            wordCountMap.put(s, this.wordCount(s));
28
+        }
29
+        return wordCountMap;
11 30
     }
12 31
 }

+ 13
- 7
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java Ver arquivo

@@ -5,31 +5,37 @@ package rocks.zipcode.quiz5.fundamentals;
5 5
  */
6 6
 public class Calculator {
7 7
     public static Double squareRoot(Double value) {
8
-        return null;
8
+        return Math.sqrt(value);
9 9
     }
10 10
 
11 11
     public static Double square(Double value) {
12
-        return null;
12
+        return value*value;
13 13
     }
14 14
 
15 15
     public static Double[] squareRoots(Double... value) {
16
-        return null;
16
+        for(int i = 0; i<value.length; i++){
17
+            value[i] = Math.sqrt(value[i]);
18
+        }
19
+        return value;
17 20
     }
18 21
 
19 22
     public static Double[] squares(Double... values) {
20
-        return null;
23
+        for(int i = 0; i<values.length; i++){
24
+            values[i] = values[i]*values[i];
25
+        }
26
+        return values;
21 27
     }
22 28
 
23 29
     public static Double add(Double value1, Double value2) {
24
-        return null;
30
+        return (Double) value1+value2;
25 31
     }
26 32
 
27 33
     public static Double subtract(Double value1, Double value2) {
28
-        return null;
34
+        return value1-value2;
29 35
     }
30 36
 
31 37
 
32 38
     public static Double divide(Double divisor, Double dividend) {
33
-        return null;
39
+        return divisor/dividend;
34 40
     }
35 41
 }

+ 41
- 7
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java Ver arquivo

@@ -1,34 +1,68 @@
1 1
 package rocks.zipcode.quiz5.fundamentals;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+
3 6
 /**
4 7
  * @author leon on 21/12/2018.
5 8
  */
6 9
 public class StringUtils {
7 10
     public static Character getMiddleCharacter(String string) {
8
-        return null;
11
+        return string.charAt(string.length()/2);
9 12
     }
10 13
 
11 14
     public static String capitalizeMiddleCharacter(String str) {
12
-        return null;
15
+        String capMiddle = "";
16
+        capMiddle = (str.substring(0, str.length()/2) + getMiddleCharacter(str).toString().toUpperCase() + str.substring(str.length()/2+1));
17
+        return capMiddle;
13 18
     }
14 19
 
15 20
     public static String lowerCaseMiddleCharacter(String str) {
16
-        return null;
21
+        String lowMiddle = "";
22
+        lowMiddle = (str.substring(0, str.length()/2) + getMiddleCharacter(str).toString().toLowerCase() + str.substring(str.length()/2+1));
23
+        return lowMiddle;
17 24
     }
18 25
 
19 26
     public static Boolean isIsogram(String str) {
20
-        return null;
27
+        char arr[] = str.toCharArray();
28
+
29
+        Arrays.sort(arr);
30
+        for(int i = 0; i<arr.length-1; i++){
31
+            if (arr[i] == arr[i+1]) {
32
+                return false;
33
+            }
34
+        }
35
+        return true;
21 36
     }
22 37
 
23 38
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
24
-        return null;
39
+        char arr[] = str.toCharArray();
40
+
41
+        for(int i = 0; i<arr.length-1; i++){
42
+            if (arr[i] == arr[i+1]) {
43
+                return true;
44
+            }
45
+        }
46
+        return false;
25 47
     }
26 48
 
27 49
     public static String removeConsecutiveDuplicateCharacters(String str) {
28
-        return null;
50
+        if(!hasDuplicateConsecutiveCharacters(str)){
51
+            return str;
52
+        }
53
+        return str;
29 54
     }
30 55
 
31 56
     public static String invertCasing(String str) {
32
-        return null;
57
+        char[] chars = str.toCharArray();
58
+        for(int i = 0; i < chars.length; i++){
59
+            char c = chars[i];
60
+            if(Character.isUpperCase(c)){
61
+                chars[i] = Character.toLowerCase(c);
62
+            } else if( Character.isLowerCase(c)){
63
+                chars[i] = Character.toUpperCase(c);
64
+            }
65
+        }
66
+        return new String(chars);
33 67
     }
34 68
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Curry.java Ver arquivo

@@ -1,4 +1,4 @@
1 1
 package rocks.zipcode.quiz5.objectorientation;
2 2
 
3
-public class Curry {
3
+public class Curry implements Spice {
4 4
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Ginger.java Ver arquivo

@@ -3,5 +3,5 @@ package rocks.zipcode.quiz5.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class Ginger {
6
+public class Ginger implements Spice {
7 7
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Pepper.java Ver arquivo

@@ -3,5 +3,5 @@ package rocks.zipcode.quiz5.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class Pepper {
6
+public class Pepper implements Spice {
7 7
 }