QuestionQuestion

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 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.

c) Write a program to create data for testing the program. Use the sample account data in Figs. 17.22 and 17.23. 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

Transaction file
Account number, Transaction amount
100 27.14
300 62.11
400 100.56
900 82.17

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’s a master record for a particular account, but no corresponding transaction record, merely write the master record to "newmast.txt". When there’s 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".

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class FileMatch {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
       // TODO code application logic here
      
       ArrayList<AccountRecord> accR = new ArrayList<>();
       ArrayList<TransactionRecord> transR = new ArrayList<>();
      
       ArrayList<TransactionRecord> unmatchedTR = new ArrayList<>();
      
       // read from file
       read(accR, transR);
      
       // update record
       boolean flag = true;
       for (TransactionRecord trans : transR) {
            flag = true;
            for (AccountRecord acc : accR) {
                if (acc.getAccount() == trans.getAccount_number()) {
                   acc.combine(trans);
                   flag = false;
                   break;
                }
            }
            if (flag) {
                unmatchedTR.add(trans);
            }
       }...
$40.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats