因此,对于作业,我必须从格式如下的输入文件中读取:
Miller <--- last name
William <---first name
00001 <--- account ID
891692 06 <--- account balance
这四行代表一个“帐户”。从一个主要方法中,我必须从另一个名为 account 的类中调用并在该类中运行一个名为 toString() 的方法
toString() 应该以这种格式打印出这四行:
00001,Miller,William,$891692.06
到目前为止,这是我的主要方法中的内容:
int count = 1;
while(read.hasNextLine()) {
String nextLine = read.nextLine();
account.toString(nextLine);
if(count %4==0) {
vector.addAccount(nextLine);
}
count++;
}
这就是我的 toString 方法中的内容:
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]);
}
在 toString 中,返回语句出现错误,并且我需要格式化 info[3](最终应该是帐户余额),以便在打印时以美元表示:$00.00
任何帮助深表感谢!谢谢!