In this exercise, you will create a class that reads customer and account data from a flat file.
Figure 9-1 shows the UML diagram for the DataSource class that you will
create for the TestReport program.
Figure 9-1 The DataSource Class Loads Customer Data from a Flat File
Code 9-1 Data File Format
<number-of-customers>
<first-name> <last-name> <number-of-accounts>
<account-type-code> <datum1> <datum2>
Code 9-2 shows an example of the format of the customer data file. This data file contains four customer records. The first is for Jane Simms; Jane has two bank accounts. The first account is a savings account, with an initial balance of 500.00 and an interest rate of 5 percent (0.05). The second account is a checking account with an initial balance of 200.00 and overdraft protection of 400.00.
Code 9-2 Example Test Data File
4
Jane Simns 2 S 500.00 0.05 C 200.00 400.00 Owen Bryant 1 C 200.00 0.00 Tim Soley 2 S 1500.00 0.05 C 200.00 0.00 Maria Soley 1 S 150.00 0.05
Before you begin, make sure that you have changed directories to projects/BankingPrj/ using the cd command in the terminal window.
cd ~/projects/ BankingPrj/
Perform the following: 1. Create the data/ directory. 2. Copy the test .dat file from the resources/mod09_textapps/ directory into the data/ directory.
On the command line, use the java command to run the test program. You should see the following output: Reading data file: ../data/teat.dat CUSTOMERS REPORT ================ Customer: Simms, Jane Savings Account: current balance is 500.0 Checking Account: current balance is 200.0 Customer: Bryant, Owen Checking Account: current balance is 200.0 Customer: Soley, Tim Savings Account: current balance is 1500.0 Checking Account: current balance is 200.0 Customer: Soley, Maria Savings Account: current balance is 150.0