// (We did not have time to complete this program in Section A, // but it is a useful example for doing Homework 3.) // // Computes the total paid hours worked by two employees. // The company does not pay for more than 8 hours per day. // Uses a "cumulative sum" loop to compute the total hours. import java.util.*; public class Hours { public static void main(String[] args) { Scanner console = new Scanner(System.in); int hours1 = processEmployee(console, 1); int hours2 = processEmployee(console, 2); int total = hours1 + hours2; System.out.println("Total paid hours for both employees = " + total); } // Reads hours information about one employee with the given number. // Returns the total hours worked by the employee. public static int processEmployee(Scanner console, int number) { System.out.print("Employee " + number + ": How many days? "); int days = console.nextInt(); // totalHours is a cumulative sum of all days' hours worked. int totalHours = 0; for (int i = 1; i <= days; i++) { System.out.print("Hours? "); int hours = console.nextInt(); hours = Math.min(hours, 8); // cap at 8 hours per day totalHours = totalHours + hours; } System.out.println("Employee " + number + "'s total paid hours = " + totalHours); System.out.println(); return totalHours; } }