Saurav Kamath vor 5 Jahren
Ursprung
Commit
00264af1ad

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/collections/Food.java Datei anzeigen

@@ -23,7 +23,7 @@ public class Food extends HashMap<Spice, Integer> {
23 23
     }
24 24
 
25 25
     public void applySpice(Spice spice) {
26
-        if(Spices.containsValue(spice)){
26
+        if(Spices.containsKey(spice)){
27 27
             Spices.put(spice, Spices.get(spice)+1);
28 28
         }else{
29 29
             Spices.put(spice, 1);

+ 9
- 3
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java Datei anzeigen

@@ -3,15 +3,21 @@ package rocks.zipcode.quiz5.collections;
3 3
 import java.util.*;
4 4
 
5 5
 public class WordCounter {
6
-
7 6
     Map<String, Integer> wordCounter= new HashMap<>();
8 7
 
9 8
     public WordCounter(String... strings) {
10
-
9
+        for(String string : strings){
10
+            if(wordCounter.containsKey(string)){
11
+                Integer newValue = wordCounter.get(string) + 1;
12
+                wordCounter.put(string, newValue);
13
+            }else{
14
+                wordCounter.put(string, 1);
15
+            }
16
+        }
11 17
 
12 18
     }
13 19
 
14 20
     public Map<String, Integer> getWordCountMap() {
15
-        return null;
21
+        return wordCounter;
16 22
     }
17 23
 }

+ 16
- 7
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java Datei anzeigen

@@ -5,31 +5,40 @@ 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
+        Double square = value*value;
13
+        return square;
13 14
     }
14 15
 
15 16
     public static Double[] squareRoots(Double... value) {
16
-        return null;
17
+        Double[] fin = new Double[value.length];
18
+        for(int i = 0; i < value.length; i++){
19
+            fin[i] = squareRoot(value[i]);
20
+        }
21
+        return fin;
17 22
     }
18 23
 
19 24
     public static Double[] squares(Double... values) {
20
-        return null;
25
+        Double[] fin = new Double[values.length];
26
+        for(int i = 0; i < values.length; i++){
27
+            fin[i] = square(values[i]);
28
+        }
29
+        return fin;
21 30
     }
22 31
 
23 32
     public static Double add(Double value1, Double value2) {
24
-        return null;
33
+        return value1 + value2;
25 34
     }
26 35
 
27 36
     public static Double subtract(Double value1, Double value2) {
28
-        return null;
37
+        return value1 - value2;
29 38
     }
30 39
 
31 40
 
32 41
     public static Double divide(Double divisor, Double dividend) {
33
-        return null;
42
+        return divisor/dividend;
34 43
     }
35 44
 }

+ 57
- 6
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java Datei anzeigen

@@ -1,23 +1,45 @@
1 1
 package rocks.zipcode.quiz5.fundamentals;
2 2
 
3
+import java.util.*;
4
+
3 5
 /**
4 6
  * @author leon on 21/12/2018.
5 7
  */
6 8
 public class StringUtils {
7 9
     public static Character getMiddleCharacter(String string) {
8
-        return null;
10
+        return string.charAt(string.length()/2);
9 11
     }
10 12
 
11 13
     public static String capitalizeMiddleCharacter(String str) {
12
-        return null;
14
+        int middle = str.length()/2;
15
+        String upper = str.substring(middle, middle+1).toUpperCase();
16
+        String[] strArray = str.split("");
17
+        strArray[middle] = upper;
18
+        String fin = "";
19
+        for(String string : strArray){
20
+            fin = fin.concat(string);
21
+        }
22
+        return fin;
23
+
13 24
     }
14 25
 
15 26
     public static String lowerCaseMiddleCharacter(String str) {
16
-        return null;
27
+        int middle = str.length()/2;
28
+        String upper = str.substring(middle, middle+1).toLowerCase();
29
+        String[] strArray = str.split("");
30
+        strArray[middle] = upper;
31
+        String fin = "";
32
+        for(String string : strArray){
33
+            fin = fin.concat(string);
34
+        }
35
+        return fin;
17 36
     }
18 37
 
19 38
     public static Boolean isIsogram(String str) {
20
-        return null;
39
+        Set<Character>  set = new HashSet<>();
40
+        for(int i = 0; i < str.length(); i++) set.add(str.charAt(i));
41
+        if(set.size() == str.length()) return true;
42
+        return false;
21 43
     }
22 44
 
23 45
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
@@ -25,10 +47,39 @@ public class StringUtils {
25 47
     }
26 48
 
27 49
     public static String removeConsecutiveDuplicateCharacters(String str) {
28
-        return null;
50
+        boolean isContinued = true;
51
+        String[] strArray = str.split("");
52
+        String fin = "";
53
+        while(isContinued){
54
+            //if(strArray)
55
+        }
56
+        return fin;
29 57
     }
30 58
 
31 59
     public static String invertCasing(String str) {
32
-        return null;
60
+        String[] strArray = str.split("");
61
+        String fin = "";
62
+        for(String string : strArray){
63
+            if(isUpperCase(string)){
64
+               String temp =  string.toLowerCase();
65
+               fin = fin.concat(temp);
66
+            }
67
+            else if(!isUpperCase(string)){
68
+               String temp = string.toUpperCase();
69
+               fin = fin.concat(temp);
70
+            }
71
+        }
72
+        return fin;
73
+    }
74
+
75
+    public static boolean isUpperCase(String s) {
76
+        for (int i=0; i<s.length(); i++)
77
+        {
78
+            if (Character.isLowerCase(s.charAt(i)))
79
+            {
80
+                return false;
81
+            }
82
+        }
83
+        return true;
33 84
     }
34 85
 }