Browse Source

working on the bank

Whitney Martinez 5 years ago
parent
commit
6a624dd90b

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Curry.java View File

@@ -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 View File

@@ -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 View File

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

+ 11
- 0
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Account.java View File

@@ -6,6 +6,17 @@ package rocks.zipcode.quiz5.objectorientation.account;
6 6
 public class Account {
7 7
 
8 8
     private Long id;
9
+    private Long number = 0L;
10
+
11
+    public Account(Long id) {
12
+        this.id = id;
13
+    }
14
+
15
+    public Account() {
16
+
17
+        this.id = number+1;
18
+
19
+    }
9 20
 
10 21
     public Long getId() {
11 22
         return id;

+ 17
- 2
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java View File

@@ -24,16 +24,31 @@ public class BankAccount extends Account implements Transactable {
24 24
 
25 25
     @Override
26 26
     public void deposit(Double amountToIncreaseBy) {
27
-        this.val += amountToIncreaseBy;
27
+        if( amountToIncreaseBy < 0) {
28
+
29
+            throw new IllegalArgumentException();
30
+
31
+        }else{
32
+            this.val += amountToIncreaseBy;
33
+        }
28 34
     }
29 35
 
30 36
     @Override
31 37
     public void withdrawal(Double amountToDecreaseBy) {
32
-        this.val -= amountToDecreaseBy;
38
+
39
+        if( val < amountToDecreaseBy) {
40
+            throw new IllegalArgumentException();
41
+        }else if(amountToDecreaseBy < 00.0) {
42
+            throw new IllegalArgumentException();
43
+
44
+        }else{
45
+            this.val -= amountToDecreaseBy;
46
+        }
33 47
     }
34 48
 
35 49
     @Override
36 50
     public Double getBalance() {
51
+
37 52
         return this.val;
38 53
     }
39 54
 }

+ 20
- 4
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java View File

@@ -5,7 +5,7 @@ package rocks.zipcode.quiz5.objectorientation.account;
5 5
 /**
6 6
  * @author leon on 30/12/2018.
7 7
  */
8
-public class Employee implements Worker {
8
+public class Employee implements Worker, Transactable {
9 9
 
10 10
     private BankAccount bankAccount;
11 11
     private Double moneyMade;
@@ -16,7 +16,8 @@ public class Employee implements Worker {
16 16
     }
17 17
 
18 18
     public Employee(BankAccount bankAccount) {
19
-
19
+        this.bankAccount = bankAccount;
20
+        this.hourlywage = getHourlyWage();
20 21
     }
21 22
 
22 23
 
@@ -39,7 +40,7 @@ public class Employee implements Worker {
39 40
 
40 41
     @Override
41 42
     public Double getHoursWorked() {
42
-        return this.hoursworked;
43
+        return hoursworked;
43 44
     }
44 45
 
45 46
     public void setHourlyWage(Double hourlywage){
@@ -49,11 +50,26 @@ public class Employee implements Worker {
49 50
 
50 51
     @Override
51 52
     public Double getHourlyWage() {
52
-        return this.hourlywage;
53
+        return hourlywage;
53 54
     }
54 55
 
55 56
     @Override
56 57
     public Double getMoneyEarned() {
57 58
         return this.moneyMade = hourlywage * hoursworked;
58 59
     }
60
+
61
+    @Override
62
+    public void deposit(Double amountToIncreaseBy) {
63
+        this.moneyMade += amountToIncreaseBy;
64
+    }
65
+
66
+    @Override
67
+    public void withdrawal(Double amountToDecreaseBy) {
68
+        this.moneyMade -= amountToDecreaseBy;
69
+    }
70
+
71
+    @Override
72
+    public Double getBalance() {
73
+        return moneyMade;
74
+    }
59 75
 }