// Processes an employee input file and outputs each employee's hours. import java.io.*; // for File import java.util.*; // for Scanner public class Hours2 { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("hours.txt")); PrintStream out = new PrintStream(new File("hours_out.txt")); while (input.hasNextLine()) { String line = input.nextLine(); processEmployee(out, line); } } public static void processEmployee(PrintStream out, String line) { Scanner lineScan = new Scanner(line); int id = lineScan.nextInt(); // e.g. 456 String name = lineScan.next(); // e.g. "Brad" double totalHours = 0.0; int days = 0; while (lineScan.hasNextDouble()) { totalHours += lineScan.nextDouble(); days++; } double average = totalHours / days; out.println(name + " (ID#" + id + ") worked " + totalHours + " hours (" + average + " hours/day)"); } }