changed used overdraft
This commit is contained in:
parent
2a0d97c834
commit
01f22b94a2
|
@ -11,7 +11,7 @@ public final class CurrentAccount extends Account {
|
|||
/**
|
||||
* Overdraft amount in currency.
|
||||
*/
|
||||
private double overdraft;
|
||||
private final double overdraft;
|
||||
|
||||
public CurrentAccount(int iban, int pin, double balance, double overdraft) {
|
||||
super(iban, pin, balance);
|
||||
|
@ -24,11 +24,9 @@ public final class CurrentAccount extends Account {
|
|||
|
||||
/**
|
||||
* Takeoff a certain amount of money from this accounts balance.
|
||||
* If amount is greater than the balance, the overflow will be added to the overdraft
|
||||
* and balance will be set to 0.
|
||||
* Saturates the result if the value to subtract is greater than the balance present.
|
||||
* @param amount the amount of money to subtract from the accounts balance
|
||||
* @throws IllegalArgumentException if amount is smaller than 0
|
||||
* @throws IllegalArgumentException if amount is smaller than 0 or the overflow is greater than the overdraft.
|
||||
*/
|
||||
@Override
|
||||
public void takeoff(double amount) throws IllegalArgumentException {
|
||||
|
@ -38,8 +36,11 @@ public final class CurrentAccount extends Account {
|
|||
|
||||
if (overflow > 0) {
|
||||
Logging.LOGGER.fine("taking off money with overflow: " + overflow);
|
||||
this.overdraft += overflow;
|
||||
this.balance = 0;
|
||||
|
||||
if (overflow > overdraft) {
|
||||
Logging.LOGGER.warning("amount to takeoff greater than overdraft");
|
||||
throw new IllegalArgumentException("amount to takeoff greater than overdraft");
|
||||
}
|
||||
}
|
||||
|
||||
this.balance -= amount;
|
||||
|
|
Loading…
Reference in New Issue