简体   繁体   English

常规输出不返回任何内容

[英]General output does not return anything

I'm trying to use Stringtokenizer to read off several lines in a file and display relevant info using a while loop (for a school project), but the general output in JCreator seems to not return anything despite any changes I make. 我正在尝试使用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

I've tried other programs to see if the output is messed up due to something wrong with Java, but other files work fine. 我尝试了其他程序来查看输出是否由于Java错误而混乱,但其他文件可以正常工作。 Is there anything here that could possibly be interfering with the output being displayed? 这里是否有可能干扰显示的输出?

The error is in the acquireValues() method: 错误发生在acquireValues()方法中:

while(line != null);

You have a ; 你有一个; which should not be there. 不应该在那里。 Remove it. 去掉它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM