1 /**
2 A bank consisting of multiple bank accounts.
3 */
4 public class Bank
5 {
6 private BankAccount[] accounts;
7
8 /**
9 Constructs a bank account with a given number of accounts.
10 @param size the number of accounts
11 */
12 public Bank(int size)
13 {
14 accounts = new BankAccount[size];
15 for (int i = 0; i < accounts.length; i++)
16 accounts[i] = new BankAccount();
17 }
18
19 /**
20 Deposits money into a bank account.
21 @param accountNumber the account number
22 @param amount the amount to deposit
23 */
24 public void deposit(int accountNumber, double amount)
25 {
26 BankAccount account = accounts[accountNumber];
27 account.deposit(amount);
28 }
29
30 /**
31 Withdraws money from a bank account.
32 @param accountNumber the account number
33 @param amount the amount to withdraw
34 */
35 public void withdraw(int accountNumber, double amount)
36 {
37 BankAccount account = accounts[accountNumber];
38 account.withdraw(amount);
39 }
40
41 /**
42 Gets the balance of a bank account.
43 @param accountNumber the account number
44 @return the account balance
45 */
46 public double getBalance(int accountNumber)
47 {
48 BankAccount account = accounts[accountNumber];
49 return account.getBalance();
50 }
51 }
52
53