Connor Dunnigan vor 5 Jahren
Ursprung
Commit
c8cd3daccf

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

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

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

@@ -13,13 +13,13 @@ public class Food {
13 13
         return spices;
14 14
     }
15 15
 
16
-    public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
17
-        Map<SpiceType, Integer> count = new HashMap<>();
16
+    public <SpiceType extends Class<? extends Spice>> Map<Class<? extends Spice> , Integer> getSpiceCount() {
17
+        Map<Class<? extends Spice>, Integer> count = new HashMap<>();
18 18
         for(Spice s : spices) {
19 19
             if (count.containsKey(s.getClass()))
20
-                count.put((SpiceType)s.getClass(), count.get(s) + 1);
20
+                count.put(s.getClass(), count.get(s.getClass()) + 1);
21 21
             else
22
-                count.put((SpiceType)s.getClass(), 1);
22
+                count.put(s.getClass(), 1);
23 23
         }
24 24
         return count;
25 25
     }

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

@@ -36,7 +36,7 @@ public class Calculator {
36 36
     }
37 37
 
38 38
     public static Double subtract(Double value1, Double value2) {
39
-        return DoubleRounder.round(value1 + value2, 2);
39
+        return value1 - value2;
40 40
     }
41 41
 
42 42
 

+ 8
- 0
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java Datei anzeigen

@@ -4,7 +4,15 @@ package rocks.zipcode.quiz5.objectorientation.account;
4 4
  * @author leon on 27/12/2018.
5 5
  */
6 6
 public class BankAccount extends Account implements Transactable{
7
+
7 8
     private Double balance;
9
+
10
+    public BankAccount(){
11
+        balance = 0.0;
12
+    }
13
+    public BankAccount(Double balance){
14
+        this.balance = balance;
15
+    }
8 16
     public void setBalance(Double val) {
9 17
         balance = val;
10 18
     }

+ 21
- 2
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java Datei anzeigen

@@ -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 Employee implements Worker{
6
+public class Employee implements Worker, Transactable{
7 7
     Double hourlyWage;
8 8
     Double hoursWorked;
9 9
     Double balance;
@@ -13,12 +13,13 @@ public class Employee implements Worker{
13 13
          hourlyWage = 35.0;
14 14
          hoursWorked = 0.0;
15 15
          balance = 0.0;
16
-         bankAccount.setBalance(0.0);
16
+         bankAccount = new BankAccount(0.0);
17 17
     }
18 18
 
19 19
     public Employee(BankAccount bankAccount) {
20 20
         this();
21 21
         this.bankAccount = bankAccount;
22
+        balance = bankAccount.getBalance();
22 23
     }
23 24
 
24 25
     public BankAccount getBankAccount() {
@@ -27,6 +28,7 @@ public class Employee implements Worker{
27 28
 
28 29
     public void setBankAccount(BankAccount bankAccount) {
29 30
         this.bankAccount = bankAccount;
31
+        balance = bankAccount.getBalance();
30 32
     }
31 33
 
32 34
     @Override
@@ -48,4 +50,21 @@ public class Employee implements Worker{
48 50
     public Double getMoneyEarned() {
49 51
         return hourlyWage * hoursWorked;
50 52
     }
53
+
54
+    @Override
55
+    public void deposit(Double amountToIncreaseBy) {
56
+        balance += amountToIncreaseBy;
57
+        bankAccount.deposit(amountToIncreaseBy);
58
+    }
59
+
60
+    @Override
61
+    public void withdrawal(Double amountToDecreaseBy) {
62
+        balance -= amountToDecreaseBy;
63
+        bankAccount.withdrawal(amountToDecreaseBy);
64
+    }
65
+
66
+    @Override
67
+    public Double getBalance() {
68
+        return balance;
69
+    }
51 70
 }