Browse Source

added code

Soujanya Buragapu 5 years ago
parent
commit
fad2048991

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

@@ -10,12 +10,12 @@ import java.util.List;
10 10
  */
11 11
 public class Bank
12 12
 {
13
+
13 14
     List<BankAccount> accounts = new ArrayList<BankAccount>();
14 15
 
15 16
     public BankAccount removeBankAccountByIndex(Integer indexNumber)
16 17
     {
17
-       //BankAccount ba = accounts.remove(indexNumber);
18
-        return null;
18
+        return accounts.remove((int)indexNumber);
19 19
     }
20 20
 
21 21
     public void addBankAccount(BankAccount bankAccount)

+ 16
- 4
src/main/java/rocks/zipcode/quiz5/collections/Food.java View File

@@ -8,8 +8,9 @@ import java.util.*;
8 8
 /**
9 9
  * @author leon on 27/12/2018.
10 10
  */
11
-public class Food implements Spice
11
+public class Food
12 12
 {
13
+    private Integer spiceAmount = 0;
13 14
     ArrayList<Spice> food = new ArrayList<Spice>();
14 15
     public List<Spice> getAllSpices()
15 16
     {
@@ -18,12 +19,23 @@ public class Food implements Spice
18 19
 
19 20
     public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount()
20 21
     {
21
-       return null;
22
+        LinkedHashMap<SpiceType, Integer> spiceCount = new LinkedHashMap<>();
23
+        for (Spice s : food) {
24
+            spiceCount.put((SpiceType) s.getClass(), s.getSpiciness());
25
+        }
26
+        for (Spice s : food) {
27
+            s.setSpiciness(0);
28
+        }
29
+        return spiceCount;
22 30
 
23 31
     }
24 32
 
25 33
     public void applySpice(Spice spice)
26 34
     {
27
-        food.add(spice);
35
+        if(!food.contains(spice)){
36
+            food.add(spice);
37
+        }
38
+        spice.setSpiciness(spice.getSpiciness()+1);
28 39
     }
29
-}
40
+    }
41
+

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

@@ -1,4 +1,19 @@
1 1
 package rocks.zipcode.quiz5.objectorientation;
2 2
 
3
-public class Curry implements Spice{
3
+public class Curry implements Spice
4
+{
5
+    private static Integer spiciness = 0;
6
+
7
+    public Curry() {
8
+
9
+    }
10
+
11
+    @Override
12
+    public void setSpiciness(Integer spiciness) {
13
+        this.spiciness=spiciness;
14
+    }
15
+
16
+    public Integer getSpiciness(){
17
+        return spiciness;
18
+    }
4 19
 }

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

@@ -3,5 +3,20 @@ package rocks.zipcode.quiz5.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class Ginger implements Spice {
6
+public class Ginger implements Spice
7
+{
8
+    private static Integer spiciness=0;
9
+
10
+    public Ginger() {
11
+
12
+    }
13
+
14
+    public Integer getSpiciness() {
15
+        return spiciness;
16
+    }
17
+
18
+    @Override
19
+    public void setSpiciness(Integer spiciness) {
20
+        this.spiciness = spiciness;
21
+    }
7 22
 }

+ 13
- 0
src/main/java/rocks/zipcode/quiz5/objectorientation/Pepper.java View File

@@ -5,5 +5,18 @@ package rocks.zipcode.quiz5.objectorientation;
5 5
  */
6 6
 public class Pepper implements Spice
7 7
 {
8
+    private static Integer spiciness=0;
8 9
 
10
+    public Pepper() {
11
+
12
+    }
13
+
14
+    public Integer getSpiciness() {
15
+        return spiciness;
16
+    }
17
+
18
+    @Override
19
+    public void setSpiciness(Integer spiciness) {
20
+        this.spiciness = spiciness;
21
+    }
9 22
 }

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

@@ -3,5 +3,8 @@ package rocks.zipcode.quiz5.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public interface Spice {
6
+public interface Spice
7
+{
8
+    void setSpiciness(Integer spiciness);
9
+    Integer getSpiciness();
7 10
 }

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

@@ -3,20 +3,15 @@ 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
6
+public class Account
7 7
 {
8
-    public Long Id;
9
-    public Account()
10
-    {
8
+    private Long id;
11 9
 
12
-    }
13
-    public Long getId()
14
-    {
15
-        return Id;
10
+    public Long getId() {
11
+        return id;
16 12
     }
17 13
 
18
-    public void setId(Long id)
19
-    {
20
-        this.Id = id;
14
+    public void setId(Long id) {
15
+        this.id = id;
21 16
     }
22 17
 }

+ 20
- 38
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java View File

@@ -3,53 +3,35 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class BankAccount implements Transactable,Worker
6
+public class BankAccount extends Account implements Transactable
7 7
 {
8
-    public Double balance;
9
-    public Double HourseWorked;
10
-    public Double HourlyWage;
11
-    public Double MoneyEarned;
12
-    public void setBalance(Double val)
13
-    {
14
-        this.balance = val;
15
-    }
16
-
17
-    @Override
18
-    public void deposit(Double amountToIncreaseBy)
19
-    {
20
-     balance += amountToIncreaseBy;
21
-    }
8
+    private double balance;
22 9
 
23
-    @Override
24
-    public void withdrawal(Double amountToDecreaseBy)
25
-    {
26
-        balance -=amountToDecreaseBy;
10
+    public void setBalance(Double val) {
11
+        balance = val;
27 12
     }
28 13
 
29 14
     @Override
30
-    public Double getBalance()
31
-    {
32
-        return balance;
33
-    }
15
+    public void deposit(Double amountToIncreaseBy) {
16
+        if (amountToIncreaseBy < 0.0){
17
+            throw new java.lang.IllegalArgumentException();
18
+        }
19
+        else {
20
+            balance += amountToIncreaseBy;
21
+        }    }
34 22
 
35 23
     @Override
36
-    public void increaseHoursWorked(Double numberOfHours)
37
-    {
38
-
24
+    public void withdrawal(Double amountToDecreaseBy) {
25
+        if (amountToDecreaseBy < 0.0 || balance < amountToDecreaseBy){
26
+            throw new java.lang.IllegalArgumentException();
27
+        }
28
+        else {
29
+            balance -= amountToDecreaseBy;
30
+        }
39 31
     }
40 32
 
41 33
     @Override
42
-    public Double getHoursWorked() {
43
-        return HourseWorked;
44
-    }
45
-
46
-    @Override
47
-    public Double getHourlyWage() {
48
-        return HourlyWage;
49
-    }
50
-
51
-    @Override
52
-    public Double getMoneyEarned() {
53
-        return MoneyEarned;
34
+    public Double getBalance() {
35
+        return balance;
54 36
     }
55 37
 }

+ 23
- 36
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java View File

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