Browse Source

almost done

thulasi 5 years ago
parent
commit
9967f3c38f

+ 9
- 4
src/main/java/rocks/zipcode/quiz5/collections/Food.java View File

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.quiz5.collections;
2 2
 
3
+import rocks.zipcode.quiz5.objectorientation.Curry;
3 4
 import rocks.zipcode.quiz5.objectorientation.Spice;
4 5
 import sun.security.provider.ConfigFile;
5 6
 
@@ -21,10 +22,14 @@ public class Food {
21 22
     public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
22 23
         Map<SpiceType, Integer> map = new HashMap<>();
23 24
         for(Spice spice : spices){
24
-//            if(!map.containsKey(spice))
25
-//                map.put(spice, 1);
26
-//            else
27
-//                map.put(spice, map.get(spice) +1);
25
+            if(spice instanceof Curry)
26
+
27
+            if(!map.containsKey(spice)){
28
+                map.put(spice, 1);
29
+            }
30
+
31
+            else
32
+                map.put(spice, map.get(spice) +1);
28 33
         }
29 34
         return map;
30 35
     }

+ 8
- 2
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java View File

@@ -1,6 +1,9 @@
1 1
 package rocks.zipcode.quiz5.fundamentals;
2 2
 
3 3
 import java.text.DecimalFormat;
4
+import java.util.ArrayList;
5
+import java.util.Arrays;
6
+import java.util.List;
4 7
 import java.util.regex.Matcher;
5 8
 
6 9
 /**
@@ -18,10 +21,12 @@ public class Calculator {
18 21
     }
19 22
 
20 23
     public static Double[] squareRoots(Double... value) {
21
-        Double[] result = new Double[value.length];
24
+        List<Double> doubles = new ArrayList<>(Arrays.asList(value));
25
+         Double[] result = new Double[value.length];
22 26
         int index = 0;
23 27
         for(Double val : value){
24 28
             result[index] = Math.sqrt(val);
29
+            index++;
25 30
         }
26 31
         return result;
27 32
     }
@@ -31,6 +36,7 @@ public class Calculator {
31 36
         int index = 0;
32 37
         for(Double val : values){
33 38
             result[index] = Double.valueOf(df2.format(Math.pow(val, 2)));
39
+            index++;
34 40
         }
35 41
         return result;
36 42
     }
@@ -42,7 +48,7 @@ public class Calculator {
42 48
 
43 49
     public static Double subtract(Double value1, Double value2) {
44 50
 
45
-        return Double.valueOf(df2.format(value1 - value2));
51
+        return value1 - value2;
46 52
     }
47 53
 
48 54
 

+ 25
- 10
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java View File

@@ -63,16 +63,20 @@ public class StringUtils {
63 63
     }
64 64
 
65 65
     public static String removeConsecutiveDuplicateCharacters(String str) {
66
-       char prev = '\0';
67
-       int k = 0;
68
-       char[] chars = str.toCharArray();
69
-       for(int i=0;i<str.length();i++){
70
-           if(prev != chars[i]){
71
-               chars[k++] = chars[i];
72
-               prev = chars[i];
73
-           }
74
-       }
75
-       return new String(chars).substring(0,k);
66
+//        char prev = '\0';
67
+//        int k = 0;
68
+//        char[] chars = str.toCharArray();
69
+//
70
+//        for (int i = 0; i < str.length(); i++)
71
+//        {
72
+//            if (prev != chars[i]) {
73
+//                chars[k++] = chars[i];
74
+//                prev = chars[i];
75
+//            }
76
+//        }
77
+
78
+  //      return new String(chars).substring(0, k);
79
+
76 80
 
77 81
        /* List<Character> list = new ArrayList<>();
78 82
         int index =0;
@@ -85,6 +89,17 @@ public class StringUtils {
85 89
 
86 90
 
87 91
         return list.toArray(new Character[0]).toString();*/
92
+
93
+       for(int i=0;i<str.length();i++){
94
+           if(i+1 < str.length() && str.charAt(i) == str.charAt(i+1))
95
+           {
96
+
97
+           }
98
+       }
99
+
100
+
101
+
102
+       return null;
88 103
     }
89 104
 
90 105
     public static String invertCasing(String str) {