将线性链接列表打印到表中



我试图将我存储在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());

     }
}

您可以使用System.out.printf()方法将字符串和整数打印到固定宽度的位置(带有对齐方式)。

您是否尝试过此

 String msg = " FirstName " + " LastName t" + " Gender t" + " Tenure t" +
                " Pay Rate t" + " Salary t"; 

最新更新