// Helene Martin, CSE 142 // Reads hours worked for several TAs and reports their overall hours worked import java.io.*; import java.util.*; /* File structure: 123 Roee 12.5 8.1 7.6 3.2 456 Hunter 4.0 11.6 6.5 2.7 12 789 Bootsie 8.0 8.0 8.0 8.0 7.5 */ public class HoursWorked { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("hours.txt")); PrintStream out = new PrintStream("hours_out.txt"); out.println("Happy Halloween!"); // processTAHours("2343 Andrew 3.23 4.432"); while (input.hasNextLine()) { String line = input.nextLine(); processTAHours(line, out); // processTAHours(line, System.out); // System.out is a PrintStream object! } } // reads and reports hours worked for a single TA public static void processTAHours(String line, PrintStream out) { Scanner lineScan = new Scanner(line); int userId = lineScan.nextInt(); String name = lineScan.next(); double hoursWorked = 0; while (lineScan.hasNextDouble()) { hoursWorked = hoursWorked + lineScan.nextDouble(); } out.println(name + " ID#" + userId + " worked " + round(hoursWorked, 1) + " hours"); } // rounds the value to the specified places public static double round(double value, int places) { return Math.round(value * Math.pow(10, places)) / Math.pow(10, places); } }