// Marty Stepp, CSE 142, Autumn 2008 // This program reads a file of TAs' hours worked and outputs how many hours // the TAs worked. // // Example input: // 123 Kim 12.5 8.1 7.6 3.2 // 456 Brad 4.0 11.6 6.5 2.7 12 // 789 Stef 8.0 7.5 // // Example output: // Kim (ID#123) worked 31.4 hours (7.9 hours/day) // Brad (ID#456) worked 36.8 hours (7.4 hours/day) // Stef (ID#789) worked 15.5 hours (7.8 hours/day) import java.io.*; // for File import java.util.*; // for Scanner public class UnderpaidTAs { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("hours.txt")); while (input.hasNextLine()) { String line = input.nextLine(); // "123 Kim 12.5 8.1 7.6 3.2" Scanner lineScanner = new Scanner(line); int id = lineScanner.nextInt(); String name = lineScanner.next(); double totalHours = 0.0; int days = 0; while (lineScanner.hasNextDouble()) { double hours = lineScanner.nextDouble(); totalHours += hours; days++; } System.out.printf("%s (ID#%d) worked %.1f hours (%.1f hours/day)\n", name, id, totalHours, (totalHours/days)); } } }