1

我正在尝试使用 Stringtokenizer 读取文件中的几行并使用while循环显示相关信息(对于学校项目),但是尽管我进行了任何更改,但 JCreator 中的一般输出似乎没有返回任何内容。

import java.io.*;
import java.util.StringTokenizer;

public class EmployeePayWeek10

{
  //file input variables
  private static FileInputStream inFile;
  private static InputStreamReader inReader;
  private static BufferedReader reader;

  //StringTokenizer variable
  private static StringTokenizer stringTkn;

  //Data variables
  private static String firstName, lastName, line;
  private static double hourlyWage;
  private static double hoursMon, hoursTue, hoursWed, hoursThu, hoursFri;
  private static double ovtMon, ovtTue, ovtWed, ovtThu, ovtFri;
  private static double ovtHoursWorked, hoursWorked, effectiveWage, roundedWage;
  private static double weeklyWage;

  public static void main(String args[]) throws IOException

  {

    startFile();
    acquireValues();
    inFile.close();


  }
    //Initializing the file
    public static void startFile() throws IOException

    {

      inFile = new FileInputStream ("C:\\!!VHSJava\\!!VHSAPCSData\\VHSP35week10data.txt");
      inReader = new InputStreamReader(inFile);
      reader = new BufferedReader(inReader);

    }
    //Acquiring data values from the .txt file
    public static void acquireValues() throws IOException

    {

     line = reader.readLine();

     while(line != null);
     {

     //Separating the series of words into tokens
     stringTkn = new StringTokenizer(line);

     //Name variables
     firstName = stringTkn.nextToken();
     lastName = stringTkn.nextToken();

     //Wage variables, defined in order of the notepad file
     hourlyWage = Double.parseDouble(stringTkn.nextToken());
     hoursMon = Double.parseDouble(stringTkn.nextToken());
     ovtMon = Double.parseDouble(stringTkn.nextToken());
     hoursTue = Double.parseDouble(stringTkn.nextToken());
     ovtTue = Double.parseDouble(stringTkn.nextToken());
     hoursWed = Double.parseDouble(stringTkn.nextToken());
     ovtWed = Double.parseDouble(stringTkn.nextToken());
     hoursThu = Double.parseDouble(stringTkn.nextToken());
     ovtThu = Double.parseDouble(stringTkn.nextToken());
     hoursFri = Double.parseDouble(stringTkn.nextToken());
     ovtFri = Double.parseDouble(stringTkn.nextToken());

     calcWage();
     returnWage();


    line = reader.readLine();

    }
    }

    //Weekly wage is calculated and rounded to two decimal places. (At most)

    public static void calcWage() throws IOException
    {

        hoursWorked = (hoursMon + hoursTue + hoursWed + hoursThu + hoursFri);
        ovtHoursWorked = (ovtMon + ovtTue + ovtWed + ovtThu + ovtFri);
        effectiveWage = (hoursWorked * hourlyWage) + (1.5 * ovtHoursWorked * hourlyWage);
        roundedWage = (double)Math.round(effectiveWage * 100) / (100);

    }

    //Calculated weekly wage is returned alongside name of employee.

    public static void returnWage() throws IOException
    {
        System.out.println(firstName + lastName + "Weekly Wage: " + roundedWage);
    }
} //End of class

我尝试了其他程序来查看是否由于 Java 出现问题而导致输出混乱,但其他文件工作正常。这里有什么可能会干扰正在显示的输出吗?

4

1 回答 1

0

错误在acquireValues()方法中:

while(line != null);

你有一个;不应该在那里。去掉它。

于 2013-11-12T05:59:36.687 回答