In Java plese comments & check output :) Cumulative sum question • Write a progr
ID: 3937053 • Letter: I
Question
In Java plese comments & check output :)
Cumulative sum question • Write a program that reads two employees' hours and displays each employee's total and the overall total • The company doesn't pay overtime; cap each day at hours. 8 hours. • Example log of execution: Employee 1 : How many days? 3 Hours? 6 EH Hours ? 12 Hours? 5 Employee 1's total hours - 19 (6.3 day) H. W 1 Employee 2: How many days? 2 Hours? 11 Hours ? 6 Employee 's total hours 2- 14 (7.0 1 day) 7 . + 8.5 Total hours for both 33 pyright 2008 Pearson Education 17 Cumulative sum answer 11 Computes the total paid hours worked by two employees. 1 company does pay for more 8 hours per . The not than day II 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 hoursl = processEmployee (console, 1) ; int hours2 = processEmployee (console, 2) ; int total = hoursl + hours2 ; systemfor = " + ); . Out.printin ("Total hours both total PYng ight 2008 Pearson Education 18Explanation / Answer
import java.util.*;
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 hours for both = "+total);
}
//Reads hours information about an employee with the given number
//Returns total hours worked by the employee
public static int processEmployee(Scanner console,int number)
{
System.out.println(" Employee "+number + " :How many days?");
int days = console.nextInt();
//totalHours is the cummulative sum of all days hours worked
int totalHours = 0;
for(int i = 1; i<=days;i++)
{
System.out.print(" Hours?");
int hours = console.nextInt();
totalHours = totalHours + Math.min(hours,8); //min(hours,8) will return minimum of the two . If hours> 8 ,it returns 8
}
double hoursPerDay = (double)totalHours/days;
System.out.printf(" Employee %d's total hours = %d(%.1f)/day) ",number,totalHours,hoursPerDay);
System.out.println();
return totalHours;
}
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.