Проблема возникает, когда я пытаюсь снять сумму, превышающую лимит овердрафта. В этом примере баланс после второго снятия не должен опускаться ниже разрешенного лимита овердрафта, но это так.
Как я могу изменить метод вывода в классе CheckingAccount, чтобы предотвратить снятие средств, превышающее лимит овердрафта?
void deposit(double amount);
void withdraw(double amount);
double getBalance();
}
abstract class BankAccount implements Account {
protected double balance;
protected String accountNumber;
public BankAccount(String accountNumber, double initialBalance) {
this.accountNumber = accountNumber;
this.balance = initialBalance;
}
@Override
public double getBalance() {
return balance;
}
}
class SavingsAccount extends BankAccount {
private double interestRate;
public SavingsAccount(String accountNumber, double initialBalance, double interestRate) {
super(accountNumber, initialBalance);
this.interestRate = interestRate;
}
public void addInterest() {
balance += balance * interestRate;
}
@Override
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
}
}
@Override
public void withdraw(double amount) {
if (amount > 0 && amount 0) {
balance += amount;
}
}
@Override
public void withdraw(double amount) {
if (amount > 0 && amount
Подробнее здесь: https://stackoverflow.com/questions/787 ... ount-class