// Marty Stepp, CSE 142, Autumn 2007 // This program reads the hours worked by two employees and // outputs the total hours for each and for both employees. import java.util.*; // so that I can use Scanner public class Hours { public static void main(String[] args) { Scanner console = new Scanner(System.in); int totalHours = 0; totalHours = totalHours + processEmployee(console, 1); totalHours = totalHours + processEmployee(console, 2); System.out.println("Total hours for both = " + totalHours); } // This method reads the hours worked by one employee // and returns the total hours. public static int processEmployee(Scanner console, int num) { System.out.print("Employee " + num + ": How many days? "); int days = console.nextInt(); // cumulative sum for hours worked each day int sum = 0; for (int i = 1; i <= days; i++) { System.out.print("Hours? "); int hours = console.nextInt(); sum += Math.min(8, hours); // cap to 8 hours in one day } System.out.println("Employee " + num + "'s total hours = " + sum); return sum; } }