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 if (input.equals("D")) { accounts[num].deposit(amount); }
41 else { accounts[num].withdraw(amount); }
42
43 System.out.println("Balance: " + accounts[num].getBalance());
44 }
45 else if (input.equals("M")) // Month end processing
46 {
47 for (int n = 0; n < accounts.length; n++)
48 {
49 accounts[n].monthEnd();
50 System.out.println(n + " " + accounts[n].getBalance());
51 }
52 }
53 else if (input == "Q")
54 {
55 done = true;
56 }
57 }
58 }
59 }