Results 1 to 3 of 3
- 10-16-2009, 07:42 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 4
- Rep Power
- 0
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(); } } }
- 10-16-2009, 07:45 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Be more specific with the question. Which parts of your current code do you need with?
- 10-17-2009, 09:47 AM #3
Member
- Join Date
- Sep 2009
- Posts
- 4
- Rep Power
- 0
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 3Java 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);
Similar Threads
-
log4j: Multiple entries on Tomcat stdout file using log.error
By pbs in forum Web FrameworksReplies: 1Last Post: 10-24-2009, 02:18 AM -
how to deserialize multiple objects in a file
By xcallmejudasx in forum Advanced JavaReplies: 11Last Post: 12-16-2008, 05:29 PM -
Autocommit Transactions
By Java Tip in forum Java TipReplies: 0Last Post: 12-22-2007, 11:26 AM -
Help with signature matching
By cachi in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:21 PM -
Log4J - transactions log
By Daniel in forum Advanced JavaReplies: 1Last Post: 06-05-2007, 05:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks