Results 1 to 3 of 3
  1. #1
    cbear315 is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default file matching multiple transactions

    I am working on a homework assignment and I am halfway finished. We had to write a file matching program to begin with, which I have completed. I need to figure out how to deal with multiple matches for the same file. Any help would be greatly appreciated.

    The problem:
    (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 Ex. 17.8 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 (which I have already added in my array in this file)

    Java Code:
    //Ex 17.9 FileMatch.java - program that uses the account number on each file
    //as the record key for matching purposes and outputs the information
    
    import java.io.File;
    import java.util.Formatter;
    import java.util.FormatterClosedException;
    import java.util.IllegalFormatException;
    import java.io.FileNotFoundException;
    
    public class CreateData
    {
        public static void main(String args[])
        {
            Formatter outOldMaster = null;
            Formatter outTrans =  null;
            AccountRecord accounts[] = new AccountRecord[4];
            TransactionRecord transactions[] = new TransactionRecord[7];
    
            //create account records
            accounts[0] = new AccountRecord(100, "Alan", "Jones", 348.17);
            accounts[1] = new AccountRecord(300, "Mary", "Smith", 27.19);
            accounts[2] = new AccountRecord(500, "Sam", "Sharp", 0.00);
            accounts[3] = new AccountRecord(700, "Suzy", "Green", -14.22);
    
            //create transactions
            transactions[0] = new TransactionRecord(100, 27.14);
            transactions[1] = new TransactionRecord(300, 62.11);
            transactions[2] = new TransactionRecord(300, 83.89);
            transactions[3] = new TransactionRecord(500, 100.56);
            transactions[4] = new TransactionRecord(700, 80.78);
            transactions[5] = new TransactionRecord(700, 82.17);
            transactions[6] = new TransactionRecord(700, 1.53);
    
            try{
                //file stream for output file
                outOldMaster = new Formatter("oldmast.txt");
    
                for (int i = 0; i < accounts.length; i++)
                {
                    outOldMaster.format("%d %s %s %.2f\n", accounts[i].getAccount(),
                            accounts[i].getFirstName(), accounts[i].getLastName(),
                            accounts[i].getBalance());
                }
    
                //file stream for output file
                outTrans = new Formatter("trans.txt");
    
                for(int i = 0; i < transactions.length; i++)
                {
                    outTrans.format("%d %.2f\n", transactions[i].getAccount(),
                            transactions[i].getAmount());
                }
            }
    
            catch(SecurityException securityException)
            {
                System.err.println( "You do not have correct access to this file");
                System.exit(1);
            }
    
            catch ( FileNotFoundException fileNotFoundException )
            {
                System.err.println( "Error creating file." );
                System.exit(1);
            }
    
            catch ( IllegalFormatException formatException )
            {
                System.err.println( "Error with output." );
                System.exit( 1 );
            }
    
            catch ( FormatterClosedException closedException )
            {
                System.err.println( "Error writing to file. File has been closed." );
                System.exit( 1 );
            }
    
            finally
            {
                if ( outOldMaster != null )
                    outOldMaster.close();
                if ( outTrans != null )
                    outTrans.close();
            }
        }
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Be more specific with the question. Which parts of your current code do you need with?

  3. #3
    cbear315 is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    Default

    Java Code:
            //create transactions
            transactions[0] = new TransactionRecord(100, 27.14);
            transactions[1] = new TransactionRecord(300, 62.11);
            transactions[2] = new TransactionRecord(300, 83.89);
            transactions[3] = new TransactionRecord(500, 100.56);
            transactions[4] = new TransactionRecord(700, 80.78);
            transactions[5] = new TransactionRecord(700, 82.17);
            transactions[6] = new TransactionRecord(700, 1.53);
    I think it needs to go in there. I need for the transactions for the record 300 to save two values to it and transaction record for 700 to save those 3

Similar Threads

  1. Replies: 1
    Last Post: 10-24-2009, 03:18 AM
  2. how to deserialize multiple objects in a file
    By xcallmejudasx in forum Advanced Java
    Replies: 11
    Last Post: 12-16-2008, 06:29 PM
  3. Autocommit Transactions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-22-2007, 12:26 PM
  4. Help with signature matching
    By cachi in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 09:21 PM
  5. Log4J - transactions log
    By Daniel in forum Advanced Java
    Replies: 1
    Last Post: 06-05-2007, 06:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •