ScottishWarrior 0 Newbie Poster

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

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 */
.
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";
    }
}

please note the next two snippets of code are for another program, but u'll need them for the above to work correctly :)

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 */

and finally

public abstract interface Sortable
{
 
    public abstract int compareTo (Sortable other);
} /* 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 )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.