Java Reference
In-Depth Information
ch12/atm/Bank.java
1
import
java.io.FileReader;
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 /**
12
Constructs a bank with no customers.
13 */
14
public
Bank()
15 {
16 customers =
new
ArrayList<Customer>();
17 }
18
19 /**
20
Reads the customer numbers and pins
21
and initializes the bank accounts.
22 @param filename
the name of the customer file
23 */
24
public void
readCustomers(String filename)
25
throws
IOException
26 {
27 Scanner in =
new
Scanner(
new
FileReader(filename));
28
while
(in.hasNext())
29 {
30
int
number = in.nextInt();
31
int
pin = in.nextInt();
32 Customer c =
new
Customer(number,
pin);
33 addCustomer(c);
34 }
35 in.close();
36 }
37
567
568