oppgave: savingsaccount
This commit is contained in:
41
src/main/java/oving7/savingsaccount/BSU.java
Normal file
41
src/main/java/oving7/savingsaccount/BSU.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package oving7.savingsaccount;
|
||||
|
||||
public class BSU extends SavingsAccount {
|
||||
private double depositedThisYear = 0.0;
|
||||
private double depositMax;
|
||||
|
||||
BSU(double interestRate, double depositMax) {
|
||||
super(interestRate);
|
||||
this.depositMax = depositMax;
|
||||
}
|
||||
|
||||
public double getTaxDeduction() {
|
||||
return depositedThisYear * 0.2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deposit(double amount) {
|
||||
if ((depositedThisYear + amount) > depositMax) {
|
||||
throw new IllegalStateException(
|
||||
"cannot deposit more than the maximum deposit, which has a value of " + depositMax);
|
||||
}
|
||||
super.deposit(amount);
|
||||
depositedThisYear += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withdraw(double amount) {
|
||||
if (amount > depositedThisYear) {
|
||||
throw new IllegalStateException(
|
||||
"cannot withdraw more than has been deposited this year, which has a value of "
|
||||
+ depositedThisYear);
|
||||
}
|
||||
super.withdraw(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endYearUpdate() {
|
||||
super.endYearUpdate();
|
||||
depositedThisYear = 0.0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user