Array of objects

Discussion in 'Java' started by cyrow, Mar 15, 2008.

  1. cyrow

    cyrow New Member

    Joined:
    Nov 19, 2007
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    //class declarations
    class Account{
    private int        accNum;
    private double     balance;
      Transaction trans;
    
    Account(int a, double b, String f, String l){
      accNum = a;
      balance = b;
       Transaction[]trans= new Transaction[10];
    }
    
    class Transaction{
    private int accNum;
    private String date;
       Transaction(int a, String d){
      accNum = a;
      date = d;
       } 
    
    Problem
    I have two files, "accounts.txt" and "transaction.txt", I am trying to read the transaction data from the transaction file into the main Account.
    //Code
    Transaction[index].trans = new Transaction(in.nextInt(), in.next());
    index = position returned by binarysearch
    //error : Transaction cannot be located, what might the problem be? Do I use
    Account.Transaction[index].trans = new Transaction(in.nextInt(), in.next());
     
    Last edited by a moderator: Mar 16, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice