Elliott Stansbury преди 5 години
родител
ревизия
124fdd30c9

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

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.quiz5.arrays;
2 2
 
3
+import com.sun.deploy.util.ArrayUtil;
4
+
3 5
 import java.util.ArrayList;
4 6
 import java.util.List;
5 7
 
@@ -40,11 +42,11 @@ public class ArrayUtils {
40 42
         List<String> list = new ArrayList();
41 43
 
42 44
         for (String value: values) {
43
-
44
-            if(value != getLastElement(values)) {
45
-                list.add(value);
46
-            }
45
+            list.add(value);
47 46
         }
48
-        return list.toArray(new String[0]);
47
+        list.remove(values.length-1);
48
+
49
+
50
+        return list.toArray(new String[list.size()]);
49 51
     }
50 52
 }

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

@@ -7,19 +7,16 @@ import java.util.ArrayList;
7 7
 /**
8 8
  * @author leon on 27/12/2018.
9 9
  */
10
-public class Bank extends ArrayList{
10
+public class Bank {
11 11
 
12 12
     ArrayList<BankAccount> bank = new ArrayList<>();
13
-    BankAccount bankAccount = new BankAccount();
14 13
 
15 14
 
16 15
     public BankAccount removeBankAccountByIndex(Integer indexNumber) {
17 16
 
18
-        for(int i = 0; i < bank.size();i++){
19
-            if(i == indexNumber){
20
-                bank.remove(indexNumber);
21
-            }
22
-        }
17
+        BankAccount bankAccount = bank.get(indexNumber);
18
+
19
+        bank.remove(bankAccount);
23 20
 
24 21
         return bankAccount;
25 22
     }

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

@@ -1,12 +1,26 @@
1 1
 package rocks.zipcode.quiz5.collections;
2 2
 
3
-import java.util.Map;
3
+import java.util.*;
4 4
 
5 5
 public class WordCounter {
6 6
     public WordCounter(String... strings) {
7
+
8
+        List<String> list = Arrays.asList(strings);
9
+
10
+//        for(String string; strings){
11
+//            int freq = Collections.frequency(list,string)
12
+//        }
13
+
7 14
     }
8 15
 
9 16
     public Map<String, Integer> getWordCountMap() {
17
+
18
+        Map<String, Integer> wordCountMap = new HashMap<>();
19
+
20
+
21
+
22
+
23
+
10 24
         return null;
11 25
     }
12 26
 }

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

@@ -59,35 +59,55 @@ public class StringUtils {
59 59
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
60 60
         char arr[] = str.toCharArray();
61 61
 
62
-        for(int i = 0; i < arr.length; i++){
63
-            for(int j = 0; j <arr.length; j++){
64
-                if(arr[i] == arr[j]){
65
-                    return false;
66
-                }
62
+        for(int i = 0; i < arr.length-1; i++){
63
+            if(arr[i] == arr[i+1]){
64
+                return true;
67 65
             }
68 66
         }
69
-        return true;
67
+        return false;
70 68
     }
71 69
 
72 70
     public static String removeConsecutiveDuplicateCharacters(String str) {
73 71
 
74
-        StringBuilder builder = new StringBuilder();
75
-
76
-        char previous = 'k';
77
-        int counter = 0;
72
+        String[] arr = str.split("");
78 73
 
79
-        char arr[] = str.toCharArray();
74
+        String letter = arr[0];
80 75
 
81
-        for(int i = 0; i < arr.length; i++){
82
-                if(previous != arr[i]){
83
-                    arr[counter++] = arr[i];
84
-                    previous = arr[i];
85
-                }
76
+        for(int i =1; i < arr.length; i++){
77
+            String next = arr[i];
78
+            if(letter.equals(next)){
79
+                arr[i] = "";
80
+                arr[i-1] = "";
86 81
             }
87
-        return new String(arr).substring(0,counter);
82
+            else{
83
+                letter = arr[i];
84
+            }
85
+        }
86
+
87
+        StringBuilder builder = new StringBuilder();
88
+        for(int i = 0; i <arr.length; i++){
89
+            builder.append(arr[i]);
90
+        }
91
+
92
+        return builder.toString();
93
+
88 94
     }
89 95
 
90 96
     public static String invertCasing(String str) {
91
-        return null;
97
+
98
+        char[] chars = str.toCharArray();
99
+        for (int i = 0; i < chars.length; i++)
100
+        {
101
+            char c = chars[i];
102
+            if (Character.isUpperCase(c))
103
+            {
104
+                chars[i] = Character.toLowerCase(c);
105
+            }
106
+            else if (Character.isLowerCase(c))
107
+            {
108
+                chars[i] = Character.toUpperCase(c);
109
+            }
110
+        }
111
+        return new String(chars);
92 112
     }
93 113
 }

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

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

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

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

@@ -3,7 +3,7 @@ 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 8
     Long id;
9 9
 
@@ -14,4 +14,22 @@ public class Account extends BankAccount {
14 14
     public void setId(Long id) {
15 15
         this.id = id;
16 16
     }
17
+
18
+    Double balance;
19
+
20
+
21
+//    @Override
22
+//    public void deposit(Double amountToIncreaseBy) {
23
+//        balance += amountToIncreaseBy;
24
+//    }
25
+//
26
+//    @Override
27
+//    public void withdrawal(Double amountToDecreaseBy) {
28
+//        balance -= amountToDecreaseBy;
29
+//    }
30
+//
31
+//    @Override
32
+//    public Double getBalance() {
33
+//        return balance;
34
+//    }
17 35
 }

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

@@ -6,7 +6,7 @@ import java.util.ArrayList;
6 6
 /**
7 7
  * @author leon on 27/12/2018.
8 8
  */
9
-public class BankAccount extends ArrayList implements Transactable{
9
+public class BankAccount extends Account implements Transactable{
10 10
 
11 11
     Double val;
12 12
 

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

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