Lab5bankSimulator.txt - import java.util.Scanner public...

This preview shows page 1 - 3 out of 7 pages.

import java.util.Scanner; public class Driver { public static Scanner in = new Scanner(System.in); static Bank bank = new Bank("Bank"); //display menu public static void displayMenu() { System.out.println("Enter your choice:"); System.out.println("a: Add new account"); System.out.println("d: Display account details"); System.out.println("p: Print all accounts"); System.out.println("u: Update account balance"); System.out.println("m: Run monthly update"); System.out.println("q: Quit"); } public static void main(String[] args) { char option = 'x'; do { displayMenu(); option = in.next().toLowerCase().charAt(0); switch(option) { case 'a': bank.addAccount(); break; case 'd': bank.displayAccount(); break; case 'p': bank.printAccountDetails(); case 'u': bank.updateAccount(); break; case 'm': bank.monthlyUpdate(); break; case 'q': break; default: System.out.println("I'm sorry, I didn't understand your choice. Please try again"); } } while (option !='q'); in.close(); System.out.println("Have a nice day!");
} } -------------------------------------------------------------------------------- ----------------------------------------------------------------------- import java.util.ArrayList; public class Bank { private static String bankName; private static ArrayList<BankAccount> accounts; private int numAccounts; public Bank(String bankName) { this.bankName = bankName; accounts = new ArrayList<BankAccount>(); } public boolean addAccount() { System.out.println("Enter details for account number #" + (accounts.size() + 1)); BankAccount newAccount = null; char option = 'x'; System.out.println("Enter 'c' for Chequing, 's' for Savings"); option = Driver.in.next().toLowerCase().charAt(0); if (option == 'c') { newAccount = new ChequingAccount(); } else if (option == 's') { newAccount = new SavingsAccount(); } else { System.out.println("I'm sorry, that's not a valid option"); } if (newAccount.addBankAccount()) { accounts.add(newAccount); System.out.println("Account created successfully");

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture