changed used overdraft

This commit is contained in:
Sven Vogel 2023-07-11 22:12:13 +02:00
parent 2a0d97c834
commit 01f22b94a2
1 changed files with 7 additions and 6 deletions

View File

@ -11,7 +11,7 @@ public final class CurrentAccount extends Account {
/** /**
* Overdraft amount in currency. * Overdraft amount in currency.
*/ */
private double overdraft; private final double overdraft;
public CurrentAccount(int iban, int pin, double balance, double overdraft) { public CurrentAccount(int iban, int pin, double balance, double overdraft) {
super(iban, pin, balance); super(iban, pin, balance);
@ -24,11 +24,9 @@ public final class CurrentAccount extends Account {
/** /**
* Takeoff a certain amount of money from this accounts balance. * 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. * 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 * @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 @Override
public void takeoff(double amount) throws IllegalArgumentException { public void takeoff(double amount) throws IllegalArgumentException {
@ -38,8 +36,11 @@ public final class CurrentAccount extends Account {
if (overflow > 0) { if (overflow > 0) {
Logging.LOGGER.fine("taking off money with overflow: " + overflow); 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; this.balance -= amount;