import java.util.*; import BankAccounts.*; public class BankAccountClient { static Random generator = new Random(); static ArrayList accounts = new ArrayList<>(); public static void main(String[] args) { //Create a random number of BankAccounts (Checking & Savings) openAccounts(); display(); //Run randomly generated transactions on randomly selected BankAccounts runTransactions(); display(); //Perform end-of-billing-cycle processing of all BankAccounts endOfCycleProcessing(); display(); } //Create a random number of BankAccounts //The type (Checking, Savings) and initial banalce are randomly generated public static void openAccounts() { int numberOfAccounts = generator.nextInt(11) + 10; //10 .. 20 for (int k = 1; k <= numberOfAccounts; k++) { double amount = (generator.nextInt(41) + 10) * 100.0; //Balance $1000 .. $5000 BankAccount acct = generator.nextBoolean() ? //Select type of account new SavingsAccount(amount) : new CheckingAccount(amount) ; accounts.add(acct); } } //Perform a random number of randomly selected deposit() and withdraw() // transactions on randomly selected BankAccounts public static void runTransactions() { int numberOfTransactions = 80 + generator.nextInt(41); //80 .. 120 for (int k = 1; k <= numberOfTransactions; k++) { //Randomly selected BankAccount BankAccount account = accounts.get( generator.nextInt(accounts.size()) ); //Random transaction amount: $100 .. $700 double amount = (generator.nextInt(7) + 1) * 100.0; if (generator.nextBoolean()) //Randomly chosen transaction account.deposit(amount); // deposit() else try { account.withdraw(amount); // withdraw() } catch (RuntimeException rtex) { //Anticipating Insufficient Funds System.out.println(rtex.getMessage() + " Account #" + account.getAccountNumber()); } } } //Perform end-of-billing-cycle processing of ALL BankAccounts public static void endOfCycleProcessing() { for (BankAccount acct : accounts) acct.endOfCycleProcessing(); } //Display a listing of ALL BankAccounts public static void display() { System.out.println(); for (BankAccount acct : accounts) System.out.println(acct); } }