Question
How to do: a Java program that matches accounts in a master file(eg: mainmaster.ser) with transactions in a transaction file (transactions.ser) . Use the account
How to do: a Java program that matches accounts in a master file(eg: mainmaster.ser) with transactions in a transaction file (transactions.ser) . Use the account number on each file to match the records.
master file (eg: mainmaster.ser) containing details about each account. As transactions occur, data is entered into a transaction file called transactions.ser
apply the transaction amounts to the mainmasterfile and and how to do new file called "newmainmaster.ser"
each file is a sequential file where records are stored in increasing account number order.
Contents of mainmaster file Main Master File Account Number Name
Column of Account #: 100
300
500
700
Name:
Alistair Smith
Susan Tom
Sherin Peter
Bill Samuel
Balance
300.00
200.00
0.00
15.00
Contents of transactions file
Column Transaction File- Account Number
100
300
300
400
1400
Transaction Amount
50.00
100.00
-10.00
100.00
500.00
- How to define class Transaction that contains an account number and amount for transaction
- a class Match to perform file matching functionality. This class should have methods that read the mainmaster and transaction files.
-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 updated records to newmainmaster file.(Account for multiple transaction records with same account number)
-When there's a master record for a particular account but no corresponding transaction record , write the master record to newmainmaster file.
-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
- how to read and display data stored in all these serialized files to help view the results of your file matching process.
// 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 CreateMasterTransactionData{
private static ObjectOutputStream outOldMaster, outTransaction;
public static void main(String[] args)
{
try
{
try
{
// file streams for output files
outOldMaster = new ObjectOutputStream(
new FileOutputStream("mainmasterfile.ser"));
outTransaction = new ObjectOutputStream(
new FileOutputStream("transactions.ser"));
}
catch (IOException io)
{
System.err.println("Error opening the file.");
}
try
{
outOldMaster.writeObject(new Account(
100, "Alistair", "Smith", 300.00));
outOldMaster.writeObject(new Account(
300, "Susan", "Tom", 200.00));
outOldMaster.writeObject(new Account(
500, "Sherin", "Peter", 0.00));
outOldMaster.writeObject(new Account(
700, "Bill", "Samuel", 15.00));
outTransaction.writeObject(
new TransactionRecord(100, 50.00));
outTransaction.writeObject(
new TransactionRecord(300, 100.00));
outTransaction.writeObject(
new TransactionRecord(300, -10.00));
outTransaction.writeObject(
new TransactionRecord(400, 100.00));
outTransaction.writeObject(
new TransactionRecord(1400, 500.00));
}
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
// 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; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started