Bläddra i källkod

pre-merge commit

jacob andersen 5 år sedan
förälder
incheckning
7139b664e6

+ 25
- 7
src/main/java/rocks/zipcode/quiz5/arrays/ArrayUtils.java Visa fil

@@ -5,18 +5,36 @@ package rocks.zipcode.quiz5.arrays;
5 5
  */
6 6
 public class ArrayUtils {
7 7
     public static String getMiddleElement(String[] values) {
8
-        return null;
8
+        return values[values.length/2];
9 9
     }
10 10
 
11
-    public static String[] removeMiddleElement(String[] values) {
12
-        return null;
11
+    public static String[] removeMiddleElement(String[] values)
12
+    {
13
+        String[] newstr = new String[values.length-1];
14
+        String MiddleElem = getMiddleElement(values);
15
+        int counter=0;
16
+        for (int i=0;i<values.length;i++)
17
+        {
18
+            if(!MiddleElem.equals(values[i])) {
19
+                newstr[counter]=values[i];
20
+                counter++;
21
+            }
22
+        }
23
+
24
+        return newstr;
13 25
     }
14 26
 
15 27
     public static String getLastElement(String[] values) {
16
-        return null;
28
+        return values[(values.length-1)];
17 29
     }
18 30
 
19
-    public static String[] removeLastElement(String[] values) {
20
-        return null;
31
+    public static String[] removeLastElement(String[] values)
32
+    {
33
+        String[] newstr = new String[values.length-1];
34
+        for (int i=0;i<values.length-1;i++){
35
+            newstr[i]=values[i];
36
+        }
37
+
38
+        return newstr;
21 39
     }
22
-}
40
+}

+ 17
- 5
src/main/java/rocks/zipcode/quiz5/collections/Bank.java Visa fil

@@ -2,18 +2,30 @@ package rocks.zipcode.quiz5.collections;
2 2
 
3 3
 import rocks.zipcode.quiz5.objectorientation.account.BankAccount;
4 4
 
5
+import java.util.ArrayList;
6
+
5 7
 /**
6 8
  * @author leon on 27/12/2018.
7 9
  */
8 10
 public class Bank {
9
-    public BankAccount removeBankAccountByIndex(Integer indexNumber) {
10
-        return null;
11
+
12
+    ArrayList bank = new ArrayList<BankAccount>();
13
+
14
+    BankAccount bankAccount = new BankAccount();
15
+
16
+    public BankAccount removeBankAccountByIndex(Integer indexNumber)
17
+    {
18
+        bank.remove(indexNumber);
19
+        return bankAccount;
11 20
     }
12 21
 
13
-    public void addBankAccount(BankAccount bankAccount) {
22
+    public void addBankAccount(BankAccount bankAccount)
23
+    {
24
+    bank.add(bankAccount);
14 25
     }
15 26
 
16
-    public Boolean containsBankAccount(BankAccount bankAccount) {
17
-        throw new UnsupportedOperationException("Method not yet implemented");
27
+    public Boolean containsBankAccount(BankAccount bankAccount)
28
+    {
29
+        return bank.contains(bankAccount);
18 30
     }
19 31
 }

+ 8
- 3
src/main/java/rocks/zipcode/quiz5/collections/Food.java Visa fil

@@ -9,14 +9,19 @@ import java.util.Map;
9 9
  * @author leon on 27/12/2018.
10 10
  */
11 11
 public class Food {
12
-    public List<Spice> getAllSpices() {
12
+
13
+    public List<Spice> getAllSpices()
14
+    {
13 15
         return null;
14 16
     }
15 17
 
16
-    public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
18
+    public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount()
19
+    {
17 20
         return null;
18 21
     }
19 22
 
20
-    public void applySpice(Spice spice) {
23
+    public void applySpice(Spice spice)
24
+    {
25
+
21 26
     }
22 27
 }

+ 10
- 3
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java Visa fil

@@ -1,12 +1,19 @@
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 {
6
-    public WordCounter(String... strings) {
7
+    public WordCounter(String... strings)
8
+    {
9
+
7 10
     }
8 11
 
9
-    public Map<String, Integer> getWordCountMap() {
10
-        return null;
12
+
13
+    public Map<String, Integer> getWordCountMap()
14
+    {
15
+        Map<String, Integer> wordMap = new HashMap <>();
16
+
17
+        return wordMap;
11 18
     }
12 19
 }

+ 23
- 11
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java Visa fil

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

+ 51
- 12
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java Visa fil

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

+ 1
- 1
src/test/java/rocks/zipcode/quiz5/fundamentals/calculator/DivideTest.java Visa fil

@@ -29,7 +29,7 @@ public class DivideTest {
29 29
     @Test
30 30
     public void test4() {
31 31
         // given
32
-        test(9.0, 63.0, 5.0);
32
+        test(12.6, 63.0, 5.0);
33 33
     }
34 34
 
35 35
     @Test