01: import java.io.BufferedReader;
02: import java.io.FileReader;
03: import java.io.IOException;
04: import java.util.ArrayList;
05: import java.util.Scanner;
06: 
07: /**
08:    A bank contains customers with bank accounts.
09: */
10: public class Bank
11: {  
12:    /**
13:       Constructs a bank with no customers.
14:    */
15:    public Bank()
16:    {  
17:       customers = new ArrayList<Customer>();
18:    }
19:    
20:    /**
21:       Reads the customer numbers and pins 
22:       and initializes the bank accounts.
23:       @param filename the name of the customer file
24:    */
25:    public void readCustomers(String filename) 
26:          throws IOException
27:    {  
28:       Scanner in = new Scanner(new FileReader(filename));
29:       boolean done = false;
30:       while (in.hasNext())
31:       {  
32:          int number = in.nextInt();
33:          int pin = in.nextInt();
34:          Customer c = new Customer(number, pin);
35:          addCustomer(c);
36:       }
37:       in.close();
38:    }
39:    
40:    /**
41:       Adds a customer to the bank.
42:       @param c the customer to add
43:    */
44:    public void addCustomer(Customer c)
45:    {  
46:       customers.add(c);
47:    }
48:    
49:    /** 
50:       Finds a customer in the bank.
51:       @param aNumber a customer number
52:       @param aPin a personal identification number
53:       @return the matching customer, or null if no customer 
54:       matches
55:    */
56:    public Customer findCustomer(int aNumber, int aPin)
57:    {  
58:       for (Customer c : customers)
59:       {  
60:          if (c.match(aNumber, aPin))
61:             return c;
62:       }
63:       return null;
64:    }
65: 
66:    private ArrayList<Customer> customers;
67: }
68: 
69: