一般输出不返回任何内容

时间:2013-11-12 05:52:15

标签: java output jcreator

我正在尝试使用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出现问题导致输出是否混乱,但其他文件工作正常。这里有什么可能干扰显示的输出吗?

1 个答案:

答案 0 :(得分:0)

错误在acquireValues()方法中:

while(line != null);

你有;不应该在那里。删除它。