| | |
Dont know where to go next.
![]() |
•
•
Join Date: Aug 2006
Posts: 1
Reputation:
Solved Threads: 0
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
please note the next two snippets of code are for another program, but u'll need them for the above to work correctly
and finally
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 )
ive been making a program to display inofrmation from a .txt file, then display this data into a linked list.
here is the code
Java Syntax (Toggle Plain Text)
import java.io.*; public class LinkListTest { protected static LinkList linkList; // Read the records from txt file into an array. static void readFromFile () { // Read in a list of customers BufferedReader file; String fullName, transaction, accountNumberString, cashNumberString; int accountNumber, cash; Customer customer; try { file = new BufferedReader (new FileReader ("customers.txt")); } catch (FileNotFoundException e) { System.out.println ("File 'customer.txt' not found."); return; // File was not found, listSize = 0. } // Count number of lines in the file. try { // If fullName is null, we have reached the end of the file. fullName = file.readLine (); while (fullName != null) { transaction = file.readLine (); accountNumberString = file.readLine (); cashNumberString = file.readLine (); try { accountNumber = Integer.parseInt (accountNumberString); cash = Integer.parseInt(cashNumberString); } catch (NumberFormatException e) { System.out.println (accountNumberString + " is not a number"); System.out.println (cashNumberString + " is not a number"); return; } // Create a new Student object. customer = new Customer (fullName, transaction, accountNumber, cash); // Insert the student into the link list. System.out.println (customer); linkList.insert (customer); fullName = file.readLine (); } file.close (); } catch (IOException e) { System.out.println ("I/O exception reading 'students.txt'"); return; } } // readFromFile method // The main program. Read a list of students into a linked list, then // output the result recursively and then iteratively. Finally output // the linked list in reverse order. static public void main (String args []) { linkList = new LinkList (); readFromFile (); } // main method } /* LinkListTest class */
Java Syntax (Toggle Plain Text)
. public class Customer implements Sortable { protected String fullName; protected String transaction; protected int accountNumber; protected int cash; public Customer (String fullName, String transaction, int accountNumber, int cash) { this.fullName = fullName; this.transaction = transaction; this.accountNumber = accountNumber; this.cash = cash; } public int compareTo (Sortable other) { Customer otherCustomer = (Customer) other; int result; result = transaction.compareTo (otherCustomer.transaction); if (result == 0) { result = fullName.compareTo (otherCustomer.fullName); if (result == 0) { if (accountNumber < otherCustomer.accountNumber) result = -1; } else if (accountNumber == otherCustomer.accountNumber) { result = 0; } else { result = 1; //} } } return result; } public String getFullName () { return fullName; } public String getTransaction () { return transaction; } public int getAccountNumber () { return accountNumber; } public int getCash () { return cash; } public String toString () { return "name "+fullName +"\n"+"transaction type "+transaction+"\n"+"Account Number "+accountNumber+"\n"+"Amount "+cash+"\n\n"; } }
Java Syntax (Toggle Plain Text)
public class SortableLinkEntry { protected Sortable element; // The entry's data. protected SortableLinkEntry link; // The link to the next entry. // Create a new link entry. public SortableLinkEntry (Sortable element, SortableLinkEntry link) { this.element = element; this.link = link; } // LinkEntry constructor // Return the element of the link entry. public Sortable getElement () { return element; } // getElement method // Return the link to the next link entry. public SortableLinkEntry getLink () { return link; } // getLink method // Set the link to the next link entry. public void setLink (SortableLinkEntry newLink) { link = newLink; } // setLink method } /* SortableLinkEntry class */
Java Syntax (Toggle Plain Text)
public abstract interface Sortable { public abstract int compareTo (Sortable other); } /* Sortable interface */
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 )
![]() |
Similar Threads
- I want to get started learning a programming language (Computer Science)
- I dont want to hack but... (IT Professionals' Lounge)
- Computer powers up, does not boot (Troubleshooting Dead Machines)
- Clickable icons in IE6 v. 2.60 dont work (Web Browsers)
- Internet explorer new windows dont open (Web Browsers)
- Outlook Takes A Few Minutes To Open (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: please help me....asap!
- Next Thread: Errors in Java using netbeans
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing system test textfields threads time title tree tutorial-sample ubuntu update windows working





