OOB
OOB
ArrayList;
import java.util.List;
// instance variables
// constructor
this.accountNumber = accountNumber;
this.balance = balance;
// methods
balance += amount;
balance -= amount;
return balance;
super(accountNumber, balance);
this.monthlyFee = monthlyFee;
@Override
balance -= monthlyFee;
super(accountNumber, balance);
this.interestRate = interestRate;
@Override
public Bank() {
accounts = new ArrayList<>();
accounts.add(account);
account.updateBalance();
total += account.getBalance();
return total;
bank.updateAccountBalances();
}
}
Aciklama :
The Account class is an abstract class that represents a bank account. It has instance variables for the
account number and balance, and a constructor to initialize these values. It also has three methods:
deposit, withdraw, and getBalance.
The updateBalance method is an abstract method that must be implemented by any concrete
subclass of Account. It is used to update the balance of the account based on some specific rule,
such as applying monthly fees or interest.
The CheckingAccount class is a concrete subclass of Account that represents a checking account. It
has an additional instance variable for the monthly fee and a constructor to initialize all of its
instance variables.
The updateBalance method in the CheckingAccount class subtracts the monthly fee from the
balance.
The SavingsAccount class is a concrete subclass of Account that represents a savings account. It has
an additional instance variable for the interest rate and a constructor to initialize all of its instance
variables.
The updateBalance method in the SavingsAccount class increases the balance by the interest rate.
The Bank class maintains a list of Account objects and has methods for adding accounts, updating
the balances of all accounts, and calculating the total balance of all accounts.
The updateAccountBalances method calls the updateBalance method on each Account object in the
list.
The getTotalBalance method calculates the total balance of all accounts by adding up the balances of
each Account object in the list.
The Main class creates a Bank object and adds a CheckingAccount and a SavingsAccount to it. It then
calls the updateAccountBalances method to update the balances of all accounts, and prints the total
balance using the getTotalBalance method.