Question

In: Computer Science

Consider the data sheet below that tracks employee hours worked over four days:    Day 1 Day...

Consider the data sheet below that tracks employee hours worked over four days:

   Day 1 Day 2 Day 3 Day 4
Employee 1 5 8 6 2
Employee 2 2 0 8 6
Employee 3 6 4 9 5
Employee 4    7 8 8 4
Employee 5   3 6 2 8
Employee 6   9 5 1 7

Based on the above information, write a Java program that performs the following tasks:

Task 1) Recreate the matrix as a two-dimensional array by hardcoding values (User input is not needed)
Task 2) Calculate and print the total number of hours worked across all employees
Task 3) Find the employee who worked the most number of hours (Hint: Total all of the columns in each row. Keep track of the "largest" row and the employee associated to that row.
Task 4) Find the employee who worked the least number of hours (Hint: Total all of the columns in each row. Keep track of the "smallest" row and the employee associated to that row.

Example run:

The total number of hours worked across all employees: 129
The employee that worked the most number of hours was Employee 4 working 27 hours
The employee that worked the least number of hours was Employee 2 working 16 hours

Note: For output, use the JOptionPane class.

Solutions

Expert Solution

import javax.swing.JOptionPane;

public class EmpHours {
   public static void main(String[] args) {
       int hours[][]={{5,8,6,2},{2,0,8,6},{6,4,9,5},{7,8,8,4},{3,6,2,8},{9,5,1,7}};
       int largest=0,smallest=0,largeSum=0,smallSum=1000;
       int total=0,sum=0;
       for(int i=0;i<hours.length;i++) {
           sum=0;
           for(int j=0;j<hours[i].length;j++) {
               sum=sum+hours[i][j];
           }
           total+=sum;
           if(sum>largeSum) {
               largest=i;
               largeSum=sum;
           }
           if(sum<smallSum) {
               smallest=i;
               smallSum=sum;
           }
       }
       String res=("The total number of hours worked across all employees: "+total+"\n");
       res=res+("The employee that worked the most number of hours was Employee "+(largest+1)+ "working "+(largeSum)+ "hours\n");
       res=res+("The employee that worked the least number of hours was Employee "+(smallest+1)+ "working "+(smallSum)+ "hours");
       JOptionPane.showMessageDialog(null, res);
   }
}
  

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Consider the following consumption data of the same individual over time (two days). Day p1 x1...
Consider the following consumption data of the same individual over time (two days). Day p1 x1 p2 x2 1 2 1 3 2 2 3 2 2 1 Part a. Is the consumer exhibiting consistent revealed preferences? Show your conclusion mathematically. Part b. What if the data of the two days above are actually coming from two different individuals?
1. Let’s say an employee is paid $15 an hour and worked 36 hours in a...
1. Let’s say an employee is paid $15 an hour and worked 36 hours in a work week and you pay overtime at 1 1/2 times for all hours over 40. What is the regular pay for this employee? What is the overtime pay for this employee? What is the total gross pay for this employee? 2. Let’s say an employee is paid $15 an hour and worked 48 hours in a work week and you pay overtime at 1...
The workers at Olisur Olive Oil Factory, work four days a week, 15 hours a day....
The workers at Olisur Olive Oil Factory, work four days a week, 15 hours a day. Each day of the week, at least the following numbers of workers are needed: on weekdays 105 workers per day; on weekends 45 workers per day. There are 165 workers in the factory. Formulate a linear programming model that will reveal a schedule for the workers to maximize the sum of their consecutive days off (define decision variables; indicate objective function, constraints, and sign...
QUESTION 1. The data for number of sleeping hours per day were recorded as below A...
QUESTION 1. The data for number of sleeping hours per day were recorded as below A sample of 15 males has a sample mean of 7.3 hours and the population standard deviation is assumed to be 1.26 hours. A sample of 18 females has a sample mean of 7.8 hours and the population standard deviation is assumed to be 1.51 hours. a) Use the P-VALUE METHOD with a 0.08 significance level to test the claim that the mean number of...
1. An employee receives an hourly wage rate of $24, with time-and-a-half for all hours worked...
1. An employee receives an hourly wage rate of $24, with time-and-a-half for all hours worked in excess of 40 during the week. Payroll data for the current week are as follows: hours worked, 44; federal income tax withheld, $145; social security tax rate, 6.0%; Medicare tax rate, 1.5%; state unemployment compensation tax, 3.4% on the first $7,000; and federal unemployment compensation tax, 0.8% on the first $7,000. What is the net amount to be paid to the employee? Round...
What if the worker initially worked 8 hours a day? Discuss, but do not draw, the...
What if the worker initially worked 8 hours a day? Discuss, but do not draw, the effect of the UBI on hours of work, based on economic theory, for someone who worked full time before UBI began.
Sally is tracking her spending. Every day for n days, Sally tracks the exact amount of...
Sally is tracking her spending. Every day for n days, Sally tracks the exact amount of dollars he spends that day, which is a nonnegative real number but not necessarily an integer. For positive integers i ≤ n, he spends xi dollars on day i. For example, on day 1, he spends x1 dollars. At the end of the n days, he calculates the average daily amount he spends on his food to be averagex = (x1 + x2 +...
At Lummins Engine Corporation, production employees work 10 hours per day, four days per week. Each...
At Lummins Engine Corporation, production employees work 10 hours per day, four days per week. Each day of the week, at least the following number of employees must be working: Monday through Friday, seven employees; Saturday and Sunday, three employees. Lummins has set the following goals, listed in order ofpriority: ■ Goal 1: Meet employee requirements with 11 workers. ■ Goal 2: The average number of weekend days off per employee should be at least 1.5 days. ■ Goal 3:...
The data below represents the bacterial growth in a liquid culture over a number of days....
The data below represents the bacterial growth in a liquid culture over a number of days. Day 0 4 8 12 16 20 Amount ×106 67 84 98 125 149 185 Find a best-fit equation to the above data trend using polynomial regression with parabolic model given as: ? = ?? + ?1? + ?2?2 After calculating the values of ao, a1, and a2, substitute these values in the above parabolic model. Plot the given data and the obtained parabolic...
Write a function called compute_pay that accepts arguments representing the hourly wage of an employee and the number of hours that employee worked this week.
Python RephactorCompute Take Home PayWrite a function called compute_pay that accepts arguments representing the hourly wage of an employee and the number of hours that employee worked this week. The function should return the take home pay owed to the employee as a floating point value rounded to two decimal places.The normal work week is 40 hours, and the company pays employees "time and a half" for overtime. So, the total wages is the sum of regular wages and overtime...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT