Add rest
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user