/* Jessica Miller, CSE 142 This program uses Scanners to read the hours the TAs have worked from an input file, processes the input by calculating the total hours worked and average hours worked/day per TA, and then uses a PrintStream to write the results into an output file. */ import java.io.*; // for File, PrintStream import java.util.*; // for Scanner public class Hours { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("hours.txt")); PrintStream output = new PrintStream("hours_out.txt"); while (input.hasNextLine()) { String line = input.nextLine(); Scanner lineScanner = new Scanner(line); processEmployee(lineScanner, output); } } public static void processEmployee(Scanner lineScanner, PrintStream output) { int id = lineScanner.nextInt(); String name = lineScanner.next(); double totalHours = 0.0; int numDays = 0; while (lineScanner.hasNextDouble()) { totalHours += lineScanner.nextDouble(); numDays++; } output.printf("%s (ID#%d) worked %.1f hours (%.2f hours/day)\n", name, id, totalHours, totalHours / numDays); } }