// Zorah Fung, CSE 142 // This program prints out the total number of hours and average hours per // day for each TA. Reads data from hours.txt and prints results to out.txt import java.io.*; import java.util.*; /* file format: 123 Alex 12.5 8.2 7.6 4.0 456 Alina 4.2 11.6 6.3 2.5 12.0 789 Ryan 16.0 12.0 8.0 20.0 7.5 */ public class HoursWorked { public static void main(String[] args) throws FileNotFoundException { Scanner fileScan = new Scanner(new File("hours.txt")); PrintStream output = new PrintStream(new File("hours_out.txt")); while (fileScan.hasNextLine()) { String line = fileScan.nextLine(); Scanner tokens = new Scanner(line); // process a single TA int id = tokens.nextInt(); String name = tokens.next(); // Read all of the hours and sum them up double totalHours = 0; int days = 0; while (tokens.hasNextDouble()) { totalHours += tokens.nextDouble(); days++; } output.println(name + " worked " + totalHours + " hours (" + totalHours / days + " hours/day)"); } } }