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

Can someone help me answer this in Java? Write a program that computes weekly ho

ID: 3690996 • Letter: C

Question

Can someone help me answer this in Java?

Write a program 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

import java.util.*;

class emp_weekly_hr
{
   public static int[] accept(int[][] a)
   {
       int i,j, sum[]=new int[8],s=0;

       Scanner scan = new Scanner(System.in);      
       for(i=0;i<8;i++)
       {
           System.out.println("Enter hours for Employee"+i);
           for(j=0;j<7;j++)
           {

               a[i][j]=scan.nextInt();
               s=s+a[i][j];
           }
           sum[i]=s;
           s=0;
       }  

       return sum;
   }

   public static int[] sort(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;
   }

   public static void print(int[] arr)
   {
       for(int i=0;i<arr.length-1;i++)
       {
           System.out.println(arr[i]);
       }
   }

   public static void main(String args[])
   {
       int a[][]=new int[8][7], sum[]=new int[8], arr[]=new int[8];

       sum=accept(a);

       arr=sort(sum);

       print(arr);
   }
}
      

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