Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 2- File Matching Write a simple file matching account receivable program using object serialization. Modify the Account class as needed. Use package name filematch_package_yourinitials

Assignment 2- File Matching Write a simple file matching account receivable program using object serialization. Modify the Account class as needed. Use package name filematch_package_yourinitials There should be a master file (eg: oldmaster.ser) containing details about each account. As transactions occur, data is entered into a transaction file.(Eg: trans.ser ) Your program should mimic a file matching process that occurs at the end of a business term period, where these transactions from the transaction file are applied to the old master file and it gets rewritten as a new master file ( eg: newmaster.ser")

image text in transcribed

A) Create a class FileMatch to perform file matching functionality. This class should have methods that read the old master and transaction files.

Case 1) When a match occurs (records with same account number appear in both master file and transaction file) update the current balance in the master record and add records to newmaster file. Account for multiple transaction records with same account number.

Case 2) When there's a master record for a particular account but no corresponding transaction record , write the master record to newmaster file.

Case 3) When there is a transaction record but no corresponding master record print to a log file the message " Unmatched transaction record for account number...". The Log file should be a text file called log.txt

B) Make sure you have programs that create test data for the master and transaction files. (Refer Sample data given above) You could also instead use the sample CreateData.java file I have attached which loads these two files.

C) Also write a program to read data stored in all the three files (oldmaster, trans, newmaster) to check the file match results.

// Serializable Account class for storing records as objects. import java.io.Serializable; public class Account implements Serializable { public static final long serialVersionUID = 1L; private int account; private String firstName; private String lastName; private double balance; // initializes an Account with default values public Account() { this(0, "", "", 0.0); // call other constructor } // initializes an Account with provided values public Account(int account, String firstName, String lastName, double balance) { this.account = account; this.firstName = firstName; this.lastName = lastName; this.balance = balance; } // set account number public void setAccount(int acct) { this.account = account; } // get account number public int getAccount() { return account; } // set first name public void setFirstName(String firstName) { this.firstName = firstName; } // get first name public String getFirstName() { return firstName; } // set last name public void setLastName(String lastName) { this.lastName = lastName; } // get last name public String getLastName() { return lastName; } // set balance public void setBalance(double balance) { this.balance = balance; } // get balance public double getBalance() { return balance; } } // end class AccountRecordSerializable 

// Create data to put into an account file and a transactions file. import java.io.IOException; import java.io.FileOutputStream; import java.io.ObjectOutputStream; public class CreateData { private static ObjectOutputStream outOldMaster, outTransaction; public static void main(String[] args) { try { try { // file streams for output files outOldMaster = new ObjectOutputStream( new FileOutputStream("oldmast.ser")); outTransaction = new ObjectOutputStream( new FileOutputStream("trans.ser")); } catch (IOException io) { System.err.println("Error opening the file."); } try { outOldMaster.writeObject(new AccountRecordSerializable( 100, "Alan", "Jones", 348.17)); outOldMaster.writeObject(new AccountRecordSerializable( 300, "Mary", "Smith", 27.19)); outOldMaster.writeObject(new AccountRecordSerializable( 500, "Sam", "Sharp", 0.00)); outOldMaster.writeObject(new AccountRecordSerializable( 700, "Suzy", "Green", -14.22)); outTransaction.writeObject( new TransactionRecord(100, 27.14)); outTransaction.writeObject( new TransactionRecord(300, 62.11)); outTransaction.writeObject( new TransactionRecord(300, -10.00)); outTransaction.writeObject( new TransactionRecord(400, 100.56)); outTransaction.writeObject( new TransactionRecord(900, 82.17)); } catch (IOException io) { System.out.println("Error writing to the files."); System.exit(1); } } finally // close the files { try { if (outTransaction != null) outTransaction.close(); if (outOldMaster != null) outOldMaster.close(); } catch (IOException io) { System.err.println("Error closing the files."); System.exit(1); } } } } // end class CreateData 
Attached are sample data for the master file and the transaction file. Master File Account Number Name Balance 100 348.17 Alan Jones 27.19 300 Mary Smith 500 Sam Sharp 0.00 uzy Green -14.22 700 Transaction File Account Number Transaction Amount (-ve values indicate payments 27.14 100 300 62.11 -10.00 300 400 100.56 82.17 900 Use the account number on each file as the record key for matching purposes. Assume that each file is a sequential file where records are stored in increasing account number order

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

What is computer neworking ?

Answered: 1 week ago