#34 Xcuello

Отворени
Xcuello заяви обединяване на 12 ревизии от Xcuello/Quiz5:master във master

+ 37
- 4
src/main/java/rocks/zipcode/quiz5/arrays/ArrayUtils.java Целия файл

@@ -1,22 +1,55 @@
1 1
 package rocks.zipcode.quiz5.arrays;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 /**
4 6
  * @author leon on 01/01/2019.
5 7
  */
6 8
 public class ArrayUtils {
7 9
     public static String getMiddleElement(String[] values) {
8
-        return null;
10
+
11
+        int halfLength = values.length / 2;
12
+        String midElement;
13
+
14
+        if (halfLength % 2 == 0) {
15
+            midElement = values[halfLength];
16
+
17
+        } else {
18
+
19
+            midElement = values[halfLength];
20
+        }
21
+
22
+        return midElement;
9 23
     }
10 24
 
11 25
     public static String[] removeMiddleElement(String[] values) {
12
-        return null;
26
+
27
+        int x = (values.length - 1) / 2;
28
+        String[] copy = new String[x * 2];
29
+
30
+        System.arraycopy(values, 0, copy, 0, x);
31
+        System.arraycopy(values, values.length - x, copy, x, x);
32
+
33
+        return copy;
13 34
     }
14 35
 
15 36
     public static String getLastElement(String[] values) {
16
-        return null;
37
+
38
+        int endOfString = values.length - 1;
39
+        String lastElement;
40
+
41
+        if (endOfString % 2 == 0) {
42
+            lastElement = values[endOfString];
43
+
44
+        } else {
45
+            lastElement = values[endOfString];
46
+        }
47
+
48
+        return lastElement;
17 49
     }
18 50
 
19 51
     public static String[] removeLastElement(String[] values) {
20
-        return null;
52
+
53
+        return Arrays.copyOf(values, values.length - 1);
21 54
     }
22 55
 }

+ 18
- 2
src/main/java/rocks/zipcode/quiz5/collections/Bank.java Целия файл

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

+ 2
- 0
src/main/java/rocks/zipcode/quiz5/collections/Food.java Целия файл

@@ -10,10 +10,12 @@ import java.util.Map;
10 10
  */
11 11
 public class Food {
12 12
     public List<Spice> getAllSpices() {
13
+
13 14
         return null;
14 15
     }
15 16
 
16 17
     public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
18
+
17 19
         return null;
18 20
     }
19 21
 

+ 24
- 1
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java Целия файл

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.quiz5.collections;
2 2
 
3
+import javax.swing.*;
4
+import java.util.HashMap;
3 5
 import java.util.Map;
4 6
 
5 7
 public class WordCounter {
@@ -7,6 +9,27 @@ public class WordCounter {
7 9
     }
8 10
 
9 11
     public Map<String, Integer> getWordCountMap() {
10
-        return null;
12
+
13
+        String s = JOptionPane.showInputDialog("Enter any text.");
14
+        String[] splitString = s.split(" ");
15
+        Map<String, Integer> hashmap = new HashMap<>();
16
+
17
+        for (int i = 0; i < splitString.length; i++) {
18
+
19
+            if (!hashmap.containsKey(splitString[i])) {
20
+                hashmap.put(splitString[i], 2);
21
+
22
+            } else {
23
+
24
+                hashmap.put(splitString[i], hashmap.get(splitString[i]) + 1);
25
+            }
26
+        }
27
+        for (Object word : hashmap.keySet()) {
28
+
29
+            hashmap.get(word);
30
+        }
31
+        return hashmap;
32
+
11 33
     }
34
+
12 35
 }

+ 26
- 7
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java Целия файл

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

+ 89
- 7
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java Целия файл

@@ -1,34 +1,116 @@
1 1
 package rocks.zipcode.quiz5.fundamentals;
2 2
 
3
+import java.util.Arrays;
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
+
11
+        int halfLength = string.length() / 2;
12
+        char midChar;
13
+
14
+        if (halfLength % 2 == 0) {
15
+
16
+            midChar = string.charAt(halfLength);
17
+
18
+        } else {
19
+
20
+            midChar = string.charAt(halfLength);
21
+        }
22
+
23
+        return midChar;
9 24
     }
10 25
 
11 26
     public static String capitalizeMiddleCharacter(String str) {
12
-        return null;
27
+
28
+        char[] charArray = str.toCharArray();
29
+
30
+        charArray[charArray.length / 2] = Character.toUpperCase(charArray[charArray.length / 2]);
31
+        String newStr = new String(charArray);
32
+
33
+        return newStr;
13 34
     }
14 35
 
15 36
     public static String lowerCaseMiddleCharacter(String str) {
16
-        return null;
37
+
38
+        char[] charArray = str.toCharArray();
39
+
40
+        charArray[charArray.length / 2] = Character.toLowerCase(charArray[charArray.length / 2]);
41
+        String newStr = new String(charArray);
42
+
43
+        return newStr;
17 44
     }
18 45
 
19 46
     public static Boolean isIsogram(String str) {
20
-        return null;
47
+
48
+        str = str.toLowerCase();
49
+        char array[] = str.toCharArray();
50
+        Arrays.sort(array);
51
+
52
+        for (int i = 0; i < str.length() - 1; i++) {
53
+
54
+            if (array[i] == array[i + 1])
55
+                return false;
56
+        }
57
+
58
+        return true;
21 59
     }
22 60
 
23 61
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
24
-        return null;
62
+
63
+        for (int i = 1; i < str.length(); i++) {
64
+
65
+            if (str.charAt(i) == str.charAt(i - 1))
66
+
67
+            return true;
68
+        }
69
+        return false;
25 70
     }
26 71
 
27 72
     public static String removeConsecutiveDuplicateCharacters(String str) {
28
-        return null;
73
+
74
+       StringBuilder sb = new StringBuilder();
75
+       String[] array = str.split("");
76
+       String letter = array[0];
77
+
78
+        for (int i = 1; i < array.length; i++) {
79
+            String nextLetter = array[i];
80
+
81
+            if(letter.equals(nextLetter)) {
82
+                array[i] = "";
83
+                array[i - 1] = "";
84
+
85
+            }else{
86
+
87
+                letter = array[i];
88
+            }
89
+        }
90
+
91
+        for(String s : array) {
92
+            sb.append(s);
93
+        }
94
+
95
+        return sb.toString();
29 96
     }
30 97
 
31 98
     public static String invertCasing(String str) {
32
-        return null;
99
+
100
+        char[] chars = str.toCharArray();
101
+
102
+        for (int i = 0; i < chars.length; i++) {
103
+            char newChars = chars[i];
104
+
105
+            if (Character.isUpperCase(newChars)) {
106
+
107
+                chars[i] = Character.toLowerCase(newChars);
108
+
109
+            } else if (Character.isLowerCase(newChars)) {
110
+
111
+                chars[i] = Character.toUpperCase(newChars);
112
+            }
113
+        }
114
+        return new String(chars);
33 115
     }
34 116
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Curry.java Целия файл

@@ -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 Целия файл

@@ -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 Целия файл

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

+ 3
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Account.java Целия файл

@@ -3,8 +3,10 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 /**
4 4
  * @author leon on 30/12/2018.
5 5
  */
6
-public class Account extends BankAccount {
6
+public class Account {
7
+
7 8
     public Long getId() {
9
+
8 10
         return null;
9 11
     }
10 12
 

+ 18
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java Целия файл

@@ -3,7 +3,24 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class BankAccount {
6
+public class BankAccount extends Account implements Transactable{
7
+
7 8
     public void setBalance(Double val) {
9
+
10
+    }
11
+
12
+    @Override
13
+    public void deposit(Double amountToIncreaseBy) {
14
+
15
+    }
16
+
17
+    @Override
18
+    public void withdrawal(Double amountToDecreaseBy) {
19
+
20
+    }
21
+
22
+    @Override
23
+    public Double getBalance() {
24
+        return null;
8 25
     }
9 26
 }

+ 44
- 3
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java Целия файл

@@ -3,18 +3,59 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 /**
4 4
  * @author leon on 30/12/2018.
5 5
  */
6
-public class Employee {
7
-    public Employee() {
8
-    }
6
+public class Employee implements Transactable, Worker {
7
+
9 8
 
10 9
     public Employee(BankAccount bankAccount) {
10
+
11
+    }
12
+
13
+    public Employee() {
14
+
11 15
     }
12 16
 
13 17
     public BankAccount getBankAccount() {
18
+
14 19
         return null;
15 20
     }
16 21
 
17 22
     public void setBankAccount(BankAccount bankAccount) {
18 23
 
19 24
     }
25
+
26
+    @Override
27
+    public void deposit(Double amountToIncreaseBy) {
28
+
29
+    }
30
+
31
+    @Override
32
+    public void withdrawal(Double amountToDecreaseBy) {
33
+
34
+    }
35
+
36
+    @Override
37
+    public Double getBalance() {
38
+        return null;
39
+    }
40
+
41
+    @Override
42
+    public void increaseHoursWorked(Double numberOfHours) {
43
+
44
+    }
45
+
46
+    @Override
47
+    public Double getHoursWorked() {
48
+        return null;
49
+    }
50
+
51
+    @Override
52
+    public Double getHourlyWage() {
53
+        return null;
54
+    }
55
+
56
+    @Override
57
+    public Double getMoneyEarned() {
58
+        return null;
59
+    }
20 60
 }
61
+

+ 2
- 0
src/test/java/rocks/zipcode/quiz5/objectorientation/account/AccountPolymorphismTest.java Целия файл

@@ -3,6 +3,8 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6
+import java.util.List;
7
+
6 8
 /**
7 9
  * @author leon on 30/12/2018.
8 10
  */