Browse Source

113 so far

Jose Bedolla 5 years ago
parent
commit
3148c33216

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

@@ -3,26 +3,23 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 /**
4 4
  * @author leon on 30/12/2018.
5 5
  */
6
-public class Account extends BankAccount implements Transactable {
7
-    public Long getId() {
8
-        return null;
9
-    }
6
+public class Account {
7
+    Long id;
10 8
 
11
-    public void setId(Long id) {
9
+    public Account() {
12 10
     }
13 11
 
14
-    @Override
15
-    public void deposit(Double amountToIncreaseBy) {
16
-
12
+    public Account(Long id) {
13
+        this.id = id;
17 14
     }
18 15
 
19
-    @Override
20
-    public void withdrawal(Double amountToDecreaseBy) {
21
-
16
+    public Long getId() {
17
+        return id;
22 18
     }
23 19
 
24
-    @Override
25
-    public Double getBalance() {
26
-        return null;
20
+    public void setId(Long id) {
21
+        this.id=id;
27 22
     }
23
+
24
+
28 25
 }

+ 33
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java View File

@@ -3,7 +3,39 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class BankAccount {
6
+public class BankAccount extends Account implements Transactable {
7
+    private Double val;
8
+
9
+    public BankAccount() {
10
+    }
11
+
12
+    public BankAccount(Long id, Double val) {
13
+        super(id);
14
+        this.val = val;
15
+    }
16
+
7 17
     public void setBalance(Double val) {
18
+        this.val =val;
19
+    }
20
+
21
+    @Override
22
+    public void deposit(Double amountToIncreaseBy) {
23
+        if (amountToIncreaseBy < 0){
24
+            throw new IllegalArgumentException("not happening");
25
+        }
26
+        val = val + amountToIncreaseBy;
27
+    }
28
+
29
+    @Override
30
+    public void withdrawal(Double amountToDecreaseBy) {
31
+        if (amountToDecreaseBy > 0.0 && amountToDecreaseBy > val){
32
+                throw new IllegalArgumentException("can't happen");
33
+            }
34
+                val = val - amountToDecreaseBy;
35
+    }
36
+
37
+    @Override
38
+    public Double getBalance() {
39
+        return val;
8 40
     }
9 41
 }

+ 47
- 2
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java View File

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