Copying and Pasting Java Code
Copying and Pasting Java Code
By Barry Burd
In Java, like in almost any computer programming language, reading data from a file can be tricky.
You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste
these lines from other peoples’ code.
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class DoPayroll {
public static void main(String args[])
throws IOException {
Scanner diskScanner =
new Scanner(new File("EmployeeInfo.txt"));
for (int empNum = 1; empNum <= 3; empNum++) {
payOneEmployee(diskScanner);
}
diskScanner.close();
}
static void payOneEmployee(Scanner aScanner) {
Employee anEmployee = new Employee();
anEmployee.setName(aScanner.nextLine());
anEmployee.setJobTitle(aScanner.nextLine());
anEmployee.cutCheck(aScanner.nextDouble());
aScanner.nextLine();
}
}