Results 1 to 7 of 7
  1. #1
    husky is offline Member
    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0

    Default pls help me, pls

    im going to create a arraylist for users' input. but i dunno how to do it

    here is wht i write, but error comes out on eclipse


    public class LoadStoreAccts {

    public static ArrayList<Account> getAccts(String file)
    {
    String aRecord;
    String accountNumber, customerName, phoneNumber, balance, activeStatus;
    StringTokenizer strings;

    try
    {
    FileReader inStream = new FileReader("test.txt");
    BufferedReader ins = new BufferedReader(inStream);
    Account anAcct = new Account();
    ArrayList<Account> anAL= new ArrayList<Account>();

    while ((aRecord=ins.readLine())!= null)
    {
    strings = new StringTokenizer(aRecord,"|");
    if (strings.countTokens() == 5) {
    accountNumber = strings.nextToken();
    customerName = strings.nextToken();
    phoneNumber = strings.nextToken();
    balance = strings.nextToken();
    activeStatus = strings.nextToken();

    anAcct = new Account(accountNumber, customerName, phoneNumber, balance, activeStatus);
    anAL.add(anAcct);

    return anAL;
    }
    }
    ins.close();
    }
    catch(IOException e)
    {
    e.printStackTrace();
    }
    }


    at here:

    anAcct = new Account(accountNumber, customerName, phoneNumber, balance, activeStatus);

    eclipse shows error


    pls help me, thx soooooooooo much everyone here

  2. #2
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    6

    Default

    Where is your Account class code?

    Also, please use [code] tags, since they make the code much easier to read.
    Last edited by CodesAway; 10-21-2009 at 04:48 AM.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  3. #3
    husky is offline Member
    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0

    Default

    here is my account class

    public class Account {

    //Attributes
    private String acctNum;
    private String name;
    private String phoneNum;
    private double balance;
    private boolean activeStatus;

    public Account() //constructor
    {
    }

    //Setters
    public Account (String acctNum, String name, String phoneNum, double balance)
    {
    this.acctNum = acctNum;
    this.name = name;
    this.phoneNum = phoneNum;
    this.balance = balance;
    activeStatus = true;
    }
    public Account (String acctNum, String name, String phoneNum, double balance, boolean activeStatus)
    {
    this.acctNum = acctNum;
    this.name = name;
    this.phoneNum = phoneNum;
    this.balance = balance;
    this.activeStatus = activeStatus;
    }

    //Account getters
    public String getAcctNum()
    {
    return acctNum;
    }

    public String getName()
    {
    return name;
    }

    public String getPhoneNum()
    {
    return phoneNum;
    }

    public double getBalance()
    {
    return balance;
    }

    public boolean getActiveStatus()
    {
    return activeStatus;
    }

    //transactions
    public double query(String acctNumber)
    {
    return balance;
    }

    public void deposit(double amount)
    {
    balance += amount;
    }

    public void withdraw(double amount)
    {
    balance = balance - amount;
    }

    //toString
    public String toString()
    {
    String output = "\n\nAccount[" + "customerName = " + name + ", accountNumber = " + acctNum +
    "\n phoneNumber = " + phoneNum + ", balance = " + balance + ", activeStatus = " + activeStatus + "],";
    return output;
    }

    }

  4. #4
    husky is offline Member
    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0

    Default

    i dunno how to create the arraylist for users' input

    pls help me

    thanks so much

  5. #5
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    6

    Default

    You're working in Eclipse, right? Well, Eclipse says "The constructor Account(String, String, String, String, String) is undefined" (and it is).

    Check the type for balance and activeStatus. In your code, these are Strings, but you need a double and boolean, respectively.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  6. #6
    husky is offline Member
    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0

    Default

    i re-initialize in LordStoreAccts class as

    String aRecord;
    String accountNumber, customerName, phoneNumber, balance, activeStatus;
    StringTokenizer strings;

    i think i dont use rite method to create the arraylist. im new to java.
    pls help
    thx

  7. #7
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    6

    Default

    Right, the problem is that your balance needs to be a double, and activeStatus needs to be a boolean, since these are the types that your constructor expect.

    In your code, you read both values from the StringTokenizer, so you get a String value. You need to convert from a String to the correct type.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •