// Helene Martin, CSE 142 // Calculates total hours worked for each TA. // Different from GasPrices.java because we don't know how many days each TA worked. import java.io.*; import java.util.*; public class HoursWorked2 { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("hours.txt")); File output = new File("out.txt"); PrintStream out = new PrintStream(output); out.println("Hi class!"); // can print anything to any PrintStream while (input.hasNextLine()) { String line = input.nextLine(); Scanner lineScan = new Scanner(line); processLine(lineScan, out); // can use same code for console output: // processLine(lineScan, System.out); } } public static void processLine(Scanner lineScan, PrintStream out) { int id = lineScan.nextInt(); String name = lineScan.next(); double totHours = 0; while (lineScan.hasNextDouble()) { double hours = lineScan.nextDouble(); totHours += hours; } out.println(name + "(" + id + "): " + totHours); } }