1  import java.io.File;
  2  import java.io.IOException;
  3  import java.util.ArrayList;
  4  import java.util.Scanner;
  5  
  6  /**
  7     A bank contains customers with bank accounts.
  8  */
  9  public class Bank
 10  {  
 11     private ArrayList<Customer> customers;
 12  
 13     /**
 14        Constructs a bank with no customers.
 15     */
 16     public Bank()
 17     {  
 18        customers = new ArrayList<Customer>();
 19     }
 20     
 21     /**
 22        Reads the customer numbers and pins 
 23        and initializes the bank accounts.
 24        @param filename the name of the customer file
 25     */
 26     public void readCustomers(String filename) 
 27           throws IOException
 28     {  
 29        Scanner in = new Scanner(new File(filename));
 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  
 67