NedRedmond hace 5 años
padre
commit
647103efba

+ 12
- 3
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java Ver fichero

@@ -4,21 +4,30 @@ 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
+    private Double balance;
8
+
9
+    public BankAccount() {
10
+        this.balance = 0D;
11
+    }
12
+
7 13
     public void setBalance(Double val) {
14
+        this.balance = val;
8 15
     }
9 16
 
10 17
     @Override
11 18
     public void deposit(Double amountToIncreaseBy) {
12
-
19
+        if (amountToIncreaseBy < 0) throw new IllegalArgumentException("try again fool");
20
+        balance += amountToIncreaseBy;
13 21
     }
14 22
 
15 23
     @Override
16 24
     public void withdrawal(Double amountToDecreaseBy) {
17
-
25
+        if (amountToDecreaseBy < 0 || (balance - amountToDecreaseBy) < 0) throw new IllegalArgumentException("try again fool");
26
+        balance -= amountToDecreaseBy;
18 27
     }
19 28
 
20 29
     @Override
21 30
     public Double getBalance() {
22
-        return null;
31
+        return balance;
23 32
     }
24 33
 }

+ 18
- 9
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java Ver fichero

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