NedRedmond 5 vuotta sitten
vanhempi
commit
647103efba

+ 12
- 3
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java Näytä tiedosto

4
  * @author leon on 27/12/2018.
4
  * @author leon on 27/12/2018.
5
  */
5
  */
6
 public class BankAccount extends Account implements Transactable {
6
 public class BankAccount extends Account implements Transactable {
7
+    private Double balance;
8
+
9
+    public BankAccount() {
10
+        this.balance = 0D;
11
+    }
12
+
7
     public void setBalance(Double val) {
13
     public void setBalance(Double val) {
14
+        this.balance = val;
8
     }
15
     }
9
 
16
 
10
     @Override
17
     @Override
11
     public void deposit(Double amountToIncreaseBy) {
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
     @Override
23
     @Override
16
     public void withdrawal(Double amountToDecreaseBy) {
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
     @Override
29
     @Override
21
     public Double getBalance() {
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 Näytä tiedosto

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