Browse Source

working on object orientation

Jennifer Chao 5 years ago
parent
commit
92bfa483b4

+ 6
- 6
src/main/java/rocks/zipcode/quiz5/collections/Bank.java View File

@@ -10,25 +10,25 @@ import java.util.List;
10 10
  */
11 11
 public class Bank {
12 12
 
13
-    private List<BankAccount> accounts;
13
+    private List<BankAccount> bankAccounts;
14 14
 
15 15
     public Bank() {
16
-        this.accounts = new ArrayList<>();
16
+        this.bankAccounts = new ArrayList<>();
17 17
     }
18 18
 
19 19
     public BankAccount removeBankAccountByIndex(Integer indexNumber) {
20
-        BankAccount bankAccount = accounts.get(indexNumber);
21
-        accounts.remove(bankAccount);
20
+        BankAccount bankAccount = bankAccounts.get(indexNumber);
21
+        bankAccounts.remove(bankAccount);
22 22
 
23 23
         return bankAccount;
24 24
     }
25 25
 
26 26
     public void addBankAccount(BankAccount bankAccount) {
27
-        accounts.add(bankAccount);
27
+        bankAccounts.add(bankAccount);
28 28
     }
29 29
 
30 30
     public Boolean containsBankAccount(BankAccount bankAccount) {
31
-        return accounts.contains(bankAccount);
31
+        return bankAccounts.contains(bankAccount);
32 32
         // throw new UnsupportedOperationException("Method not yet implemented");
33 33
     }
34 34
 }

+ 10
- 0
src/main/java/rocks/zipcode/quiz5/collections/Food.java View File

@@ -2,6 +2,8 @@ package rocks.zipcode.quiz5.collections;
2 2
 
3 3
 import rocks.zipcode.quiz5.objectorientation.Spice;
4 4
 
5
+import java.util.ArrayList;
6
+import java.util.HashMap;
5 7
 import java.util.List;
6 8
 import java.util.Map;
7 9
 
@@ -9,8 +11,16 @@ import java.util.Map;
9 11
  * @author leon on 27/12/2018.
10 12
  */
11 13
 public class Food {
14
+
15
+    private Map<Class<? extends Spice>, Integer> spices;
16
+
17
+    public Food() {
18
+        this.spices = new HashMap<>();
19
+    }
20
+
12 21
     public List<Spice> getAllSpices() {
13 22
         return null;
23
+       // return new ArrayList<>(spices.keySet());
14 24
     }
15 25
 
16 26
     public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {

+ 13
- 2
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Account.java View File

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

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

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

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

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