Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program(JAVA) that computes weekly hours for each employee. Store the we

ID: 3690649 • Letter: W

Question

Write a program(JAVA) that computes weekly hours for each employee. Store the weekly hours for all employees in a two-dimensional array. Each row records an employee’s seven-day work hours with seven columns. For example, the following array stores the work hours for eight employees. Display employees and the total hours of each employee in decreasing order of the total hours.

Su M T W R F Sa

Employee0 2 4 3 4 5 8 8

Employee1 7 3 4 3 3 4 4

Employee2 3 3 4 3 3 2 2

Employee3 9 3 4 7 3 4 1

Employee4 3 5 4 3 6 3 8

Employee5 3 4 4 6 3 4 4

Employee6 3 7 4 8 3 8 4

Employee7 6 3 5 9 2 7 9

Requirements:

1. Design a method that takes the 2-D array of weekly hours of all employees as an input parameter, calculates the sum of the total hours of all employees and returns the total hour results in an array.

2. Design a method to sort the above returned array in Requirement 1 in descending order by selection sort. • Important: when sorting the array, the program should keep track of which employee corresponds to how many work hours. Therefore, you should store the employee information in an array and return it as a result of your sort method.

3. Design a method to display the results of employees and their total hours in decreasing order.

4. Design a main method that uses the short hand initializer to initialize the 2-D array of weekly hours of all employees and invokes all the three methods in Requirements 1-3 in a sequence

Explanation / Answer

EmpWorkingHours.java

package org.students;

import java.util.Scanner;

public class EmpWorkingHours {

   public static void main(String[] args)
   {
       String arr[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
       int whours[][]=new int[8][7];
       //Creating The Scanner Object to get the Inputs from the user.
       Scanner sc=new Scanner(System.in);
       //Getting the working hours of all the employees from the user and stored in an array.
       for(int i=0;i<8;i++)
       {
           for(int j=0;j<7;j++)
           {
               System.out.print("Employee "+i+" working hours On "+arr[j]+" ::");
               whours[i][j]=sc.nextInt();
              
           }
       }
       //Displaying working hours of all the employees.
       System.out.println(" Su M T W Th F Sat");
for(int i=0;i<8;i++)
{ System.out.print("Employee "+i);
   for(int j=0;j<7;j++)
   {
      
       System.out.print(" "+whours[i][j]);
   }
   System.out.println(" ");
}
//Calling the method which calculate the total working hours of each employee
int eachEmpTWH[]=eachEmployeeTWH(whours);
//displaying Total Working Hours of each employee
for(int k=0;k<eachEmpTWH.length;k++)
{
   System.out.println(" Total Working hours of Employee "+k+" :"+eachEmpTWH[k]);
     
}

//calling the Selection sort method for sorting
int seempWH[]=doSelectionSort(eachEmpTWH);
//calling the method which sort total working hours of each employee in decending order
empTWdecOrder(seempWH);
  


   }
//method contains code which sort total working hours of each employee in decending order
   private static void empTWdecOrder(int[] seempWH) {
System.out.println(" ");
System.out.println("Employee and his Working hours in decending order ::");
           for(int i=seempWH.length-1; i>=0; i--) {
              
               System.out.println("Employee "+i+" Working Hours ::"+ seempWH[i]);
           }
      
   }
   //the Selection sort method for sorting each employee total working hours
   public static int[] doSelectionSort(int[] arr){

   for (int i = 0; i < arr.length - 1; i++)
   {
   int index = i;
   for (int j = i + 1; j < arr.length; j++)
   if (arr[j] < arr[index])
   index = j;
  
   int smallerNumber = arr[index];
   arr[index] = arr[i];
   arr[i] = smallerNumber;
   }
   return arr;
   }
  
//Method which calculate the total working hours of each employee
   private static int [] eachEmployeeTWH(int[][] whours)
   { int empTWH[]=new int[8];
       for(int i=0;i<whours.length;i++)
       { int sum=0;
           for(int j=0;j<whours[i].length;j++)
           {
               sum+=whours[i][j];
           }
           empTWH[i]=sum;
          
       }
       return empTWH;
   }

}

________________________________________________________________________________________

output:

Employee 0 working hours On Sunday ::5
Employee 0 working hours On Monday ::6
Employee 0 working hours On Tuesday ::8
Employee 0 working hours On Wednesday ::9
Employee 0 working hours On Thursday ::8
Employee 0 working hours On Friday ::7
Employee 0 working hours On Saturday ::6
Employee 1 working hours On Sunday ::5
Employee 1 working hours On Monday ::5
Employee 1 working hours On Tuesday ::4
Employee 1 working hours On Wednesday ::8
Employee 1 working hours On Thursday ::7
Employee 1 working hours On Friday ::9
Employee 1 working hours On Saturday ::5
Employee 2 working hours On Sunday ::3
Employee 2 working hours On Monday ::5
Employee 2 working hours On Tuesday ::6
Employee 2 working hours On Wednesday ::3
Employee 2 working hours On Thursday ::8
Employee 2 working hours On Friday ::7
Employee 2 working hours On Saturday ::6
Employee 3 working hours On Sunday ::9
Employee 3 working hours On Monday ::5
Employee 3 working hours On Tuesday ::4
Employee 3 working hours On Wednesday ::7
Employee 3 working hours On Thursday ::3
Employee 3 working hours On Friday ::2
Employee 3 working hours On Saturday ::5
Employee 4 working hours On Sunday ::7
Employee 4 working hours On Monday ::8
Employee 4 working hours On Tuesday ::6
Employee 4 working hours On Wednesday ::9
Employee 4 working hours On Thursday ::4
Employee 4 working hours On Friday ::5
Employee 4 working hours On Saturday ::3
Employee 5 working hours On Sunday ::6
Employee 5 working hours On Monday ::7
Employee 5 working hours On Tuesday ::8
Employee 5 working hours On Wednesday ::4
Employee 5 working hours On Thursday ::5
Employee 5 working hours On Friday ::8
Employee 5 working hours On Saturday ::9
Employee 6 working hours On Sunday ::8
Employee 6 working hours On Monday ::6
Employee 6 working hours On Tuesday ::5
Employee 6 working hours On Wednesday ::4
Employee 6 working hours On Thursday ::3
Employee 6 working hours On Friday ::7
Employee 6 working hours On Saturday ::8
Employee 7 working hours On Sunday ::6
Employee 7 working hours On Monday ::7
Employee 7 working hours On Tuesday ::6
Employee 7 working hours On Wednesday ::5
Employee 7 working hours On Thursday ::4
Employee 7 working hours On Friday ::8
Employee 7 working hours On Saturday ::9
       Su   M   T   W   Th   F   Sat
Employee 0   5   6   8   9   8   7   6

Employee 1   5   5   4   8   7   9   5

Employee 2   3   5   6   3   8   7   6

Employee 3   9   5   4   7   3   2   5

Employee 4   7   8   6   9   4   5   3

Employee 5   6   7   8   4   5   8   9

Employee 6   8   6   5   4   3   7   8

Employee 7   6   7   6   5   4   8   9


Total Working hours of Employee 0 :49

Total Working hours of Employee 1 :43

Total Working hours of Employee 2 :38

Total Working hours of Employee 3 :35

Total Working hours of Employee 4 :42

Total Working hours of Employee 5 :47

Total Working hours of Employee 6 :41

Total Working hours of Employee 7 :45

Employee and his Working hours in decending order ::

Employee 7 Working Hours ::49
Employee 6 Working Hours ::47
Employee 5 Working Hours ::45
Employee 4 Working Hours ::43
Employee 3 Working Hours ::42
Employee 2 Working Hours ::41
Employee 1 Working Hours ::38
Employee 0 Working Hours ::35

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote