/** * A little class to simulate some of the actions of a retail bank * with a passbooks savings account. * (Using a lot of imagination) * * @author gtowell * Created: Nov 2023 */ public class Bank { BankAccount[] accounts = null; int accountNumber = 2; int activeAccounts; public Bank(int size) { accounts = new BankAccount[size]; activeAccounts = 0; } private String nextAccountNumber() { accountNumber *= 1.5; String nextNum = "" + accountNumber; while (nextNum.length() < 9) { nextNum = " " + nextNum; } return nextNum; } public BankAccount makeAccount(String name, double initialDeposit) { BankAccount ba = new BankAccount(name, nextAccountNumber(), initialDeposit); accounts[activeAccounts] = ba; activeAccounts++; return ba; } public void listAccounts() { for (int i = 0; i < activeAccounts; i++) { System.out.println(accounts[i]); } } public BankAccount getAccountFromNumber(String accNum) { for (int i = 0; i < activeAccounts; i++) { if (accNum.equals(accounts[i].getAccountNumber())) { return accounts[i]; } } return null; } }