// Helene Martin, CSE 142 // Reads in a structured file of TA work hours and reports // total hours worked in a week and average hours worked per day. import java.io.*; import java.util.*; /* file format: 123 Eden 12.5 8.1 7.6 3.2 456 Hunter 4.0 11.6 6.5 2.7 12 789 Zorah 8.0 8.0 8.0 8.0 7.5 */ public class HoursWorked { public static void main(String[] args) throws FileNotFoundException { Scanner fileScan = new Scanner(new File("hours.txt")); while (fileScan.hasNextLine()) { String dataLine = fileScan.nextLine(); // process one person Scanner lineScan = new Scanner(dataLine); int id = lineScan.nextInt(); String name = lineScan.next(); double totalHours = 0.0; int days = 0; while (lineScan.hasNextDouble()) { totalHours += lineScan.nextDouble(); days++; } System.out.println(name + " (ID#" + id + ") worked " + totalHours + " hours (" + (totalHours / days) + " hours/day)"); } } }