Files
TDT4100/src/main/java/inheritance/SavingsAccount2.java
2021-08-29 20:36:32 +02:00

39 lines
860 B
Java

package inheritance;
public class SavingsAccount2 extends AbstractAccount {
int withdrawals;
int withdrawalCount;
double fee;
public SavingsAccount2(int withdrawals, double fee) {
this.setWithdrawals(withdrawals);
this.setFee(fee);
}
public void setWithdrawals(int withdrawals) {
if (withdrawals < 0)
throw new IllegalArgumentException();
this.withdrawals = withdrawals;
}
public void setFee(double fee) {
if (fee < 0)
throw new IllegalArgumentException();
this.fee = fee;
}
@Override
public void internalWithdraw(double amount) {
if (withdrawalCount >= withdrawals)
amount += fee;
if (this.balance - amount < 0)
throw new IllegalStateException("The account does not contain enough money for the withdrawal.");
withdrawalCount++;
super.balance -= amount;
}
}