From 01f22b94a25e7af73ba74a1bd5dd65bd6d9a2a37 Mon Sep 17 00:00:00 2001 From: teridax Date: Tue, 11 Jul 2023 22:12:13 +0200 Subject: [PATCH] changed used overdraft --- .../jcash/banking/accounts/CurrentAccount.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/me/teridax/jcash/banking/accounts/CurrentAccount.java b/src/me/teridax/jcash/banking/accounts/CurrentAccount.java index 97ced18..22af9ff 100644 --- a/src/me/teridax/jcash/banking/accounts/CurrentAccount.java +++ b/src/me/teridax/jcash/banking/accounts/CurrentAccount.java @@ -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;