So for an assignment I have to read from a input file that is formated as so:
Miller <— last name
William <—first name
00001 <— account ID
891692 06 <— account balance
These four lines represent an “account”. From a main method I have to call from another class called account and run a method in that class called toString()
toString() is supposed to print out those four lines in this format:
00001, Miller, William, $891692.06
Here’s what I have in my main method so far:
int count = 1;
while(read.hasNextLine()) {
String nextLine = read.nextLine();
account.toString(nextLine);
if(count %4==0) {
vector.addAccount(nextLine);
}
count++;
}
And this is whats in my toString method:
public String toString(String line) {
for(int i = 0; i < position; i++){
line = info[i];
position++;
}
return System.out.println(info[2]+", "+info[0]+", "+info[1]+", "+info[3]);
}
In toString I’m getting an error with the return statement and also I need to format info[3](which should end up being the account balance) so that it will be in dollar notation when it prints like: $00.00
Any help is much appreciated! Thanks!
Incorporating Nambari’s tip, you should try it as the following code:
And the toString method: