// Helene Martin, CSE 142 // Calculates total hours worked and average hours worked per day // for TAs in the hours.txt data file. // (This is an example of a data file for which line-based file // reading is more appropriate than token-based reading) import java.io.*; import java.util.*; public class Hours { public static void main(String[] args) throws FileNotFoundException { File f = new File("hours.txt"); Scanner input = new Scanner(f); while (input.hasNextLine()) { String line = input.nextLine(); Scanner lineScan = new Scanner(line); int id = lineScan.nextInt(); String name = lineScan.next(); double hours = 0; int days = 0; while (lineScan.hasNextDouble()) { hours += lineScan.nextDouble(); // double h = input.nextDouble(); // hours = hours + h; days++; } System.out.println(name + " (ID#" + id + ") worked " + hours + " hours (" + (hours / days) + " hours/day)"); } } }