Hi All,
Please kindly help me to identify the problem, I use Eclipse IDE
public class Emp { private String name; private String jobTitle; public void setName(String nameIn){ name=nameIn; } public String getName(){ return name; } public void setTitle(String TitleIn){ jobTitle=TitleIn; } public String getTitle(){ return jobTitle; } public void cutCheck(double amountPaid){ System.out.println("Pay to the order ", name); System.out.println("***$", jobTitle); System.out.println("",amountPaid); } }
import java.util.Scanner; import java.io.File; import java.io.IOException; public class TestClass { public static void main(String args[]) throws IOException{ Scanner diskScanner=new Scanner(new File("emp.txt")); for (int empNum=1; empNum<=3;empNum++){ payOneEmp(diskScanner); } // diskScanner.close(); } static void payOneEmp(Scanner aScanner) { Emp anEmp=new Emp(); anEmp.setName(aScanner.nextLine()); anEmp.setTitle(aScanner.nextLine()); anEmp.cutCheck(aScanner.nextDouble()); aScanner.nextLine(); } }
<terminated> TestClass
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at TestClass.payOneEmp(TestClass.java:21)
at TestClass.main(TestClass.java:13)