import java.util.*;
import java.io.*;
public class PayrollDemo{
public static void main(String[]args) throws FileNotFoundException {
Scanner input = new Scanner("Output.txt");
Employee employee = readEmployee(input); // <------ error here
input.useDelimiter("\t");
while(input.hasNext())
{
readEmployee(input);
printDetail(employee);
}
input.close();
}
public static Employee readEmployee(Scanner s)
{
String name = s.next();
int id = s.nextInt(); // <------ error here
double hourlyPayRate = s.nextDouble();
double hoursWorked = s.nextDouble();
Employee emp = new Employee(name, id);
emp.SethourlyPayRate(hourlyPayRate);
emp.SethoursWorked(hoursWorked);
return emp;
}
public static void printDetail(Employee e)
{
System.out.printf(e.getName()+ " " + e.getId()+ " " + e.GethourlyPayRate()+ " " + e.GethoursWorked()+ " " +e.GetGrossPay());
}
}
私のコードは、スキャナから int を読み取らず、次のメッセージを返します: NoSuchElementException. また、エラーは Employee employee readEmployee(input) も指しています。