Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Match {
- public ArrayList<Account> readOldMaster() throws FileNotFoundException, IOException, ClassNotFoundException {
- ArrayList<Account> masterAccount = new ArrayList<Account>();
- try (ObjectInputStream input = new ObjectInputStream(new FileInputStream("mainmasterfile.ser"))) {
- while (true) {
- masterAccount.add((Account) (input.readObject()));
- }
- } catch (EOFException e) {
- }
- return masterAccount;
- }
- public ArrayList<TransactionRecord> readTransaction() throws FileNotFoundException, IOException, ClassNotFoundException {
- ArrayList<TransactionRecord> masterRecord = new ArrayList<TransactionRecord>();
- try (ObjectInputStream input = new ObjectInputStream(new FileInputStream("transactions.ser"))) {
- while (true) {
- masterRecord.add((TransactionRecord) (input.readObject()));
- }
- } catch (EOFException e) {
- }
- return masterRecord;
- }
- public ArrayList<Account> readNewMaster() throws FileNotFoundException, IOException, ClassNotFoundException {
- ArrayList<Account> newMasterAccount = new ArrayList<Account>();
- try (ObjectInputStream input = new ObjectInputStream(new FileInputStream("newmainmaster.ser"))) {
- while (true) {
- newMasterAccount.add((Account) (input.readObject()));
- }
- } catch (EOFException e) {
- }
- return newMasterAccount;
- }
- public void matchFiles() throws FileNotFoundException, IOException, ClassNotFoundException {
- ObjectOutputStream outNewMainMaster = new ObjectOutputStream(new FileOutputStream("newmainmaster.ser"));
- ArrayList<Account> oldMaster = this.readOldMaster();
- ArrayList<TransactionRecord> Records = this.readTransaction();
- for (TransactionRecord Trans : Records) {
- boolean seenAccount = false;
- for (Account Item : oldMaster) {
- if (Item.getAccount() == Trans.getAccount()) {
- double newbalance;
- newbalance = Trans.getAmount() + Item.getBalance();
- Item.setBalance(newbalance);
- seenAccount = true;
- }
- }
- if (!seenAccount) {
- FileWriter File = new FileWriter("log.txt");
- PrintWriter Print = new PrintWriter(File);
- Print.printf("unmatched transaction record for account number..." + Trans.getAccount());
- Print.close();
- }
- }
- for (Account Item : oldMaster) {
- outNewMainMaster.writeObject(Item);
- }
- if (outNewMainMaster != null)
- outNewMainMaster.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement