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 に何か問題があるために出力が台無しになっているかどうかを確認するために他のプログラムを試してみましたが、他のファイルは正常に動作します。表示されている出力を妨害している可能性があるものはありますか?