Problem

(File Matching with Object Serialization) Recreate your solution for Exercise using object...

(File Matching with Object Serialization) Recreate your solution for Exercise using object serialization. Use the statements from Exercise  as your basis for this program. You may want to create applications to read the data stored in the .ser files—the code in Section 17.5.2 can be modified for this purpose.

Exercise

(File Matching with Multiple Transactions) It’s possible (and actually common) to have several transaction records with the same record key. This situation occurs, for example, when a customer makes several purchases and cash payments during a business period. Rewrite your accounts receivable file-matching program from Exercise to provide for the possibility of handling several transaction records with the same record key. Modify the test data of CreateData.java to include the additional transaction records in Fig..

Exercise

(File Matching) Self-Review Exercise asked you to write a series of single statements. Actually, these statements form the core of an important type of file-processing program, namely, a file-matching program. In commercial data processing, it’s common to have several files in each application system. In an accounts receivable system, for example, there is generally a master file containing detailed information about each customer, such as the customer’s name, address, telephone number, outstanding balance, credit limit, discount terms, contract arrangements and possibly a condensed history of recent purchases and cash payments.

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 programs. 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 payments 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 AccountRecord in Fig. to include method combine, which takes a TransactionRecord object and combines the balance of the AccountRecord object and the amount value of the TransactionRecord object.

Fig. | AccountRecord class maintains information for one account.


c) Write a program to create data for testing the program. Use the sample account data in Figs.. Run the program to create the files trans.txt and oldmast.txt, to be used by your file-matching program.

Fig. | Sample data for master file.

Fig. | 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., records with the same account number appear in both the master file and the transaction file), add the dollar amount in the transaction record to the current balance in the master record, and write the "newmast.txt" record. (Assume that purchases are indicated by positive amounts in the transaction file and payments by negative amounts.) When there is a master record for a particular account, but no corresponding transaction record, merely write the master record to "newmast.txt". When there is a transaction record, but no corresponding master record, print to a log file the message "Unmatched transaction record for account number…" (fill in the account number from the transaction record). The log file should be a text file named "log.txt".

Exercise

Complete the following tasks, assuming that each applies to the same program:

a) Open file “oldmast.txt” for input—use Scanner variable inOldMaster.


b) Open file “trans.txt” for input—use Scanner variable inTransaction.


c) Write a statement that opens file “newmast.txt” for output (and creation)—use formatter variable outNewMaster.


d) Read a record from the file “oldmast.txt”. Use the data to create an object of class Ac-countRecord—use Scanner variable inOldMaster. Assume that class AccountRecord is the same as the AccountRecord class in Fig..

Fig. | AccountRecord class maintains information for one account.


e) Read a record from the file “trans.txt”. The record is an object of class Transaction-Record—use Scanner variable inTransaction. Assume that class TransactionRecord contains method setAccount (which takes an int) to set the account number and method setAmount (which takes a double) to set the amount of the transaction.


f) Output a record to the file “newmast.txt”. The record is an object of type AccountRe-cord—use Formatter variable outNewMaster.

Fig. | Additional transaction records.

Exercise

Complete the following tasks, assuming that each applies to the same program:

a) Write a statement that opens file “oldmast.ser” for input—use ObjectInputStream variable inOldMaster to wrap a FileInputStream object.


b) Write a statement that opens file “trans.ser” for input—use ObjectInputStream variable inTransaction to wrap a FileInputStream object.


c) Write a statement that opens file “newmast.ser” for output (and creation)—use ObjectOutputStream variable outNewMaster to wrap a FileOutputStream.


d) Write a statement that reads a record from the file “oldmast.ser”. The record is an object of class AccountRecordSerializable—use ObjectInputStream variable inOld-Master. Assume class AccountRecordSerializable is the same as the

AccountRecord-Serializable class in Fig.

Fig. | AccountRecordSerializable class for serializable objects.


e) Write a statement that reads a record from the file “trans.ser”. The record is an object of class TransactionRecord—use ObjectInputStream variable inTransaction.


f) Write a statement that outputs a record of type AccountRecordSerializable to the file “newmast.ser”—use ObjectOutputStream variable outNewMaster.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 17
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT