oppgave: abstractaccount
This commit is contained in:
@@ -15,7 +15,8 @@ package oving7.abstractaccount;
|
||||
*/
|
||||
public class SavingsAccount extends AbstractAccount {
|
||||
|
||||
// TODO: Add fields here
|
||||
private int withdrawals;
|
||||
private double fee;
|
||||
|
||||
/**
|
||||
* Initializes a new {@code SavingsAccount} with the specified number of
|
||||
@@ -27,8 +28,22 @@ public class SavingsAccount extends AbstractAccount {
|
||||
* negative
|
||||
*/
|
||||
public SavingsAccount(int withdrawals, double fee) {
|
||||
// TODO: Implement this constructor
|
||||
if (withdrawals < 0 || fee < 0.0) {
|
||||
throw new IllegalArgumentException("cannot have less than zero withdrawals or fee of less than zero");
|
||||
}
|
||||
this.withdrawals = withdrawals;
|
||||
this.fee = fee;
|
||||
}
|
||||
|
||||
// TODO: Override abstract method here
|
||||
protected void internalWithdraw(double amount) {
|
||||
withdrawals -= 1;
|
||||
double s = amount;
|
||||
if (withdrawals < 0) {
|
||||
s += fee;
|
||||
}
|
||||
if (balance < s) {
|
||||
throw new IllegalArgumentException("balance not great enough to cover fees");
|
||||
}
|
||||
balance -= s;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user