1 import java.io.Serializable;
2 import java.util.ArrayList;
3
4 /**
5 This bank contains a collection of bank accounts.
6 */
7 public class Bank implements Serializable
8 {
9 private ArrayList<BankAccount> accounts;
10
11 /**
12 Constructs a bank with no bank accounts.
13 */
14 public Bank()
15 {
16 accounts = new ArrayList<BankAccount>();
17 }
18
19 /**
20 Adds an account to this bank.
21 @param a the account to add
22 */
23 public void addAccount(BankAccount a)
24 {
25 accounts.add(a);
26 }
27
28 /**
29 Finds a bank account with a given number.
30 @param accountNumber the number to find
31 @return the account with the given number, or null if there
32 is no such account
33 */
34 public BankAccount find(int accountNumber)
35 {
36 for (BankAccount a : accounts)
37 {
38 if (a.getAccountNumber() == accountNumber) // Found a match
39 {
40 return a;
41 }
42 }
43 return null; // No match in the entire array list
44 }
45 }