Files
oops/src/main/java/oving7/savingsaccount/BSU.java

42 lines
982 B
Java

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