我的代码是从一个看起来像这样的随机文件中读取的:(但中间没有空行)
Amy 12.23 7.43 4
杰克9.01 23.34 3Alan 34.00 34.21 7
文件将始终具有此格式,但可以是任意数量的行。我编写了一个看起来像这样的.txt文档来测试我的代码。当我试图在命令行上运行时没有任何事情发生。任何建议为什么以及我能做些什么来解决这个问题?
import java.util.Scanner;
import java.io.*;
public class EmployeePay {
public static void main(String[] args) throws FileNotFoundException {
if (args.length != 1) {
final String msg = "Usage: EmployeePay name_of_input file";
System.err.println(msg);
throw new IllegalArgumentException(msg);
}
int linesCount = 0;
final String inputFileName = args[0];
final File input = new File (inputFileName);
final Scanner scanner = new Scanner(new FileReader(input));
while (scanner.hasNextLine()) {
linesCount = linesCount +1;
}
String identification[] = new String[linesCount];
double workTime [] = new double [linesCount];
double moneyPerHour [] = new double [linesCount];
int totalDeductions [] = new int [linesCount];
for(int i = 0; i < linesCount; i++){
String line = scanner.nextLine();
String [] lineParts = line.split(" ");
identification[i]= lineParts[0];
workTime[i]= Double.valueOf(lineParts[1]);
moneyPerHour[i] = Double.valueOf(lineParts[2]);
totalDeductions[i] = Integer.parseInt(lineParts[3]);
double totalGrossPay = 0.00;
if ((workTime[i] >= 1.0) && (moneyPerHour[i] >= 15) && (totalDeductions[i]>0)&&(totalDeductions[i]<35)){
double totalPay[] = new double[linesCount];
totalPay[i] = workTime[i] *moneyPerHour[i];
totalGrossPay += totalPay[i];
double theTaxRate = 0.15;
double taxTotal = theTaxRate * totalGrossPay;
double max = Double.MIN_VALUE;
for (int a =0; a< linesCount; a++) {
if (totalPay[a] > max) {
max = totalPay[a];
}
}
System.out.println(totalGrossPay);
System.out.println(taxTotal);
System.out.println(max);
}
}
}
}