Results 1 to 7 of 7
Thread: pls help me, pls
- 10-21-2009, 03:12 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 4
- Rep Power
- 0
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
- 10-21-2009, 03:45 AM #2
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 03:48 AM.
CodesAway - codesaway.info
writing tools that make writing code a little easier
- 10-21-2009, 03:51 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 4
- Rep Power
- 0
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;
}
}
- 10-21-2009, 03:51 AM #4
Member
- Join Date
- Oct 2009
- Posts
- 4
- Rep Power
- 0
i dunno how to create the arraylist for users' input
pls help me
thanks so much
- 10-21-2009, 03:57 AM #5
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
- 10-21-2009, 04:12 AM #6
Member
- Join Date
- Oct 2009
- Posts
- 4
- Rep Power
- 0
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
- 10-21-2009, 04:16 AM #7
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


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks