Java Reference
In-Depth Information
As transactions occur (i.e., sales are made and payments arrive in the mail), information about
them is entered into a file. At the end of each business period (a month for some companies, a
week for others, and a day in some cases), the file of transactions (called
"trans.txt"
) is applied to
the master file (called
"oldmast.txt"
) to update each account's purchase and payment record.
During an update, the master file is rewritten as the file
"newmast.txt"
, which is then used at the
end of the next business period to begin the updating process again.
File-matching programs must deal with certain problems that do not arise in single-file pro-
grams. For example, a match does not always occur. If a customer on the master file has not made
any purchases or cash payments in the current business period, no record for this customer will
appear on the transaction file. Similarly, a customer who did make some purchases or cash pay-
ments could have just moved to this community, and if so, the company may not have had a
chance to create a master record for this customer.
Write a complete file-matching accounts receivable program. Use the account number on
each file as the record key for matching purposes. Assume that each file is a sequential text file with
records stored in increasing account-number order.
a)
Define class
TransactionRecord
. Objects of this class contain an account number and
amount for the transaction. Provide methods to modify and retrieve these values.
b)
Modify class
Account
in Fig. 15.9 to include method
combine
, which takes a
Transac-
tionRecord
object and combines the balance of the
Account
object and the amount val-
ue of the
TransactionRecord
object.
c)
Write a program to create data for testing the program. Use the sample account data in
Figs. 15.14 and 15.15. Run the program to create the files
trans.txt
and
oldmast.txt
to be used by your file-matching program.
Master file
account number
Name
Balance
100
Alan Jones
348.17
300
Mary Smith
27.19
500
Sam Sharp
0.00
700
Suzy Green
-14.22
Fig. 15.14
|
Sample data for master file.
Transaction file
account number
Transaction
amount
100
27.14
300
62.11
400
100.56
900
82.17
Fig. 15.15
|
Sample data for transaction file.
d)
Create class
FileMatch
to perform the file-matching functionality. The class should
contain methods that read
oldmast.txt
and
trans.txt
. When a match occurs (i.e., re-
cords with the same account number appear in both the master file and the transaction