This commit is contained in:
2021-08-29 20:36:32 +02:00
parent acf2b751a5
commit 6ea11e55c1
50 changed files with 1856 additions and 9 deletions
@@ -0,0 +1,38 @@
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;
}
}