我正在尝试将我存储到 LLL 中的一些值打印到可读表中。我存储的数据如下:
DEBBIE STARR F 3 W 1000.00
JOAN JACOBUS F 9 W 925.00
DAVID RENN M 3 H 4.75
ALBERT CAHANA M 3 H 18.75
DOUGLAS SHEER M 5 W 250.00
SHARI BUCHMAN F 9 W 325.00
SARA JONES F 1 H 7.50
RICKY MOFSEN M 6 H 12.50
JEAN BRENNAN F 6 H 5.40
JAMIE MICHAELS F 8 W 150.00
我已将每个名字、姓氏、性别、任期、工资率和薪水存储到他们自己的列表中。并且希望能够以与在我从中读取它们的文本文件中查看它们的格式相同的格式打印出来。我弄乱了一些允许我遍历和打印列表的方法,但我最终得到了丑陋的输出。. .
这是我存储文本文件的代码和我想打印的格式:
public class Payroll
{
private LineWriter lw;
private ObjectList output;
ListNode input;
private ObjectList firstname, lastname, gender, tenure, rate, salary;
public Payroll(LineWriter lw)
{
this.lw = lw;
this.firstname = new ObjectList();
this.lastname = new ObjectList();
this.gender = new ObjectList();
this.tenure = new ObjectList();
this.rate = new ObjectList();
this.salary = new ObjectList();
this.output = new ObjectList();
this.input = new ListNode();
}
public void readfile()
{
File file = new File("payfile.txt");
try{
Scanner scanner = new Scanner(file);
while(scanner.hasNextLine())
{
String line = scanner.nextLine();
Scanner lineScanner = new Scanner(line);
lineScanner.useDelimiter("\\s+");
while(lineScanner.hasNext())
{
firstname.insert1(lineScanner.next());
lastname.insert1(lineScanner.next());
gender.insert1(lineScanner.next());
tenure.insert1(lineScanner.next());
rate.insert1(lineScanner.next());
salary.insert1(lineScanner.next());
}
}
}catch(FileNotFoundException e)
{e.printStackTrace();}
}
public void printer(LineWriter lw)
{
String msg = " FirstName " + " LastName " + " Gender " + " Tenure " +
" Pay Rate " + " Salary ";
output.insert1(msg);
System.out.println(output.getFirst());
System.out.println(" " + firstname.getFirst() + " " + lastname.getFirst() + "\t" + gender.getFirst() +
"\t" + tenure.getFirst() + "\t" + rate.getFirst() + "\t" + salary.getFirst());
}
}