      1  import java.util.Scanner;

      2

      3  /**

      4     This program simulates a bank with checking and savings accounts.

      5  */

      6  public class AccountDemo

      7  {

      8     public static void main(String[] args)

      9     {

     10        // Create accounts

     11

     12        final int ACCOUNTS_SIZE = 10;

     13        BankAccount[] accounts = new BankAccount[ACCOUNTS_SIZE];

     14        for (int i = 0; i < accounts.length / 2; i++)

     15        {

     16           accounts[i] = new CheckingAccount();

     17        }

     18

     19        for (int i = accounts.length / 2; i < accounts.length; i++)

     20        {

     21           SavingsAccount account = new SavingsAccount();

     22           account.setInterestRate(0.75);

     23           accounts[i] = account;

     24        }

     25

     26        // Execute commands

     27

     28        Scanner in = new Scanner(System.in);

     29        boolean done = false;

     30        while (!done)

     31        {

     32           System.out.print("D)eposit  W)ithdraw  M)onth end  Q)uit: ");

     33           String input = in.next();

     34           if (input.equals("D") || input.equals("W")) // Deposit or withdrawal

     35           {

     36              System.out.print("Enter account number and amount: ");

     37              int num = in.nextInt();

     38              double amount = in.nextDouble();

     39

     40

     41              if (input.equals("D")) { accounts[num].deposit(amount); }

     42              else { accounts[num].withdraw(amount); }

     43

     44              System.out.println("Balance: " + accounts[num].getBalance());

     45           }

     46           else if (input.equals("M")) // Month end processing

     47           {

     48              for (int n = 0; n < accounts.length; n++)

     49              {

     50                 accounts[n].monthEnd();

     51                 System.out.println(n + " " + accounts[n].getBalance());

     52              }

     53           }

     54           else if (input == "Q")

     55           {

     56              done = true;

     57           }

     58        }

     59     }

     60  }