Dont know where to go next.

Reply

Join Date: Aug 2006
Posts: 1
Reputation: ScottishWarrior is an unknown quantity at this point 
Solved Threads: 0
ScottishWarrior ScottishWarrior is offline Offline
Newbie Poster

Dont know where to go next.

 
0
  #1
Aug 22nd, 2006
Hi there.
ive been making a program to display inofrmation from a .txt file, then display this data into a linked list.
here is the code
  1. import java.io.*;
  2. public class LinkListTest
  3. {
  4. protected static LinkList linkList;
  5. // Read the records from txt file into an array.
  6. static void readFromFile ()
  7. {
  8. // Read in a list of customers
  9. BufferedReader file;
  10. String fullName, transaction, accountNumberString, cashNumberString;
  11. int accountNumber, cash;
  12. Customer customer;
  13. try
  14. {
  15. file = new BufferedReader (new FileReader ("customers.txt"));
  16. }
  17. catch (FileNotFoundException e)
  18. {
  19. System.out.println ("File 'customer.txt' not found.");
  20. return; // File was not found, listSize = 0.
  21. }
  22. // Count number of lines in the file.
  23. try
  24. {
  25. // If fullName is null, we have reached the end of the file.
  26. fullName = file.readLine ();
  27. while (fullName != null)
  28. {
  29. transaction = file.readLine ();
  30. accountNumberString = file.readLine ();
  31. cashNumberString = file.readLine ();
  32. try
  33. {
  34. accountNumber = Integer.parseInt (accountNumberString);
  35. cash = Integer.parseInt(cashNumberString);
  36. }
  37. catch (NumberFormatException e)
  38. {
  39. System.out.println (accountNumberString +
  40. " is not a number");
  41. System.out.println (cashNumberString +
  42. " is not a number");
  43. return;
  44. }
  45. // Create a new Student object.
  46. customer =
  47. new Customer (fullName, transaction, accountNumber, cash);
  48. // Insert the student into the link list.
  49. System.out.println (customer);
  50. linkList.insert (customer);
  51. fullName = file.readLine ();
  52. }
  53. file.close ();
  54. }
  55. catch (IOException e)
  56. {
  57. System.out.println ("I/O exception reading 'students.txt'");
  58. return;
  59. }
  60. } // readFromFile method
  61. // The main program. Read a list of students into a linked list, then
  62. // output the result recursively and then iteratively. Finally output
  63. // the linked list in reverse order.
  64. static public void main (String args [])
  65. {
  66. linkList = new LinkList ();
  67. readFromFile ();
  68. } // main method
  69. } /* LinkListTest class */

  1. .
  2. public class Customer implements Sortable
  3. {
  4.  
  5. protected String fullName;
  6. protected String transaction;
  7. protected int accountNumber;
  8. protected int cash;
  9.  
  10. public Customer (String fullName, String transaction, int accountNumber, int cash)
  11. {
  12. this.fullName = fullName;
  13. this.transaction = transaction;
  14. this.accountNumber = accountNumber;
  15. this.cash = cash;
  16. }
  17. public int compareTo (Sortable other)
  18. {
  19. Customer otherCustomer = (Customer) other;
  20. int result;
  21. result = transaction.compareTo (otherCustomer.transaction);
  22. if (result == 0)
  23. {
  24. result = fullName.compareTo (otherCustomer.fullName);
  25. if (result == 0)
  26. {
  27. if (accountNumber < otherCustomer.accountNumber)
  28. result = -1;
  29. }
  30. else if (accountNumber == otherCustomer.accountNumber)
  31. {
  32. result = 0;
  33. }
  34. else
  35. {
  36. result = 1;
  37. //}
  38. }
  39. }
  40. return result;
  41. }
  42. public String getFullName ()
  43. {
  44. return fullName;
  45. }
  46. public String getTransaction ()
  47. {
  48. return transaction;
  49. }
  50. public int getAccountNumber ()
  51. {
  52. return accountNumber;
  53. }
  54. public int getCash ()
  55. {
  56. return cash;
  57. }
  58. public String toString ()
  59. {
  60. return "name "+fullName +"\n"+"transaction type "+transaction+"\n"+"Account Number "+accountNumber+"\n"+"Amount "+cash+"\n\n";
  61. }
  62. }
please note the next two snippets of code are for another program, but u'll need them for the above to work correctly
  1. public class SortableLinkEntry
  2. {
  3. protected Sortable element; // The entry's data.
  4. protected SortableLinkEntry link; // The link to the next entry.
  5. // Create a new link entry.
  6. public SortableLinkEntry (Sortable element, SortableLinkEntry link)
  7. {
  8. this.element = element;
  9. this.link = link;
  10. } // LinkEntry constructor
  11. // Return the element of the link entry.
  12. public Sortable getElement ()
  13. {
  14. return element;
  15. } // getElement method
  16. // Return the link to the next link entry.
  17. public SortableLinkEntry getLink ()
  18. {
  19. return link;
  20. } // getLink method
  21. // Set the link to the next link entry.
  22. public void setLink (SortableLinkEntry newLink)
  23. {
  24. link = newLink;
  25. } // setLink method
  26. } /* SortableLinkEntry class */
and finally
  1. public abstract interface Sortable
  2. {
  3.  
  4. public abstract int compareTo (Sortable other);
  5. } /* Sortable interface */
what i ideally want is a menu system, that will let me select the following.
Viewing withdrawl's and deposits in 2 seperate lists.
Viewing the averages of cash for each list.
could anyone point me i nthe correct direction? ( please ntoe im not asking someone to do the whole thing for me. I merely want a lil kick in the right direction - as im not sure myself )
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC