Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

I have attached the assignment’s instructions Below is the work I have done so far, I am having

I have attached the assignment’s instructions
Below is the work I have done so far, I am having

issues figuring out how to sort the array in descending order by the number of hours worked while keeping the names of the employees next to the hours they worked.

import java.util.Scanner;

public class EmployeeWorkHours {

   //Method to calculated number of hours worked

   public static int getHoursWorked(int[] hours)

   {

      int hoursWorked = 0;

      for(int i = 0; i< hours.length; i++)

      {

         hoursWorked += hours[i];

      }

      return hoursWorked;

   }

   //Method to sort array by number of hours worked

   public static void descendingSort(int[][] m) {

   }

   //Main

   public static void main(String[] args)

   {

      //Declare Variables

      Scanner in = new Scanner(System.in);

      int numEmployees, numWorkDays;

      //Prompt user for number of employees and number of days in the work week

      System.out.print(“Please enter the number of employees: “);

      numEmployees = in.nextInt();

      System.out.print(“Please enter the number of days in the work week (Must be between 1 and 7 days): “);

      numWorkDays = in.nextInt();

      //Validates User input

      while(numWorkDays <= 0 || numWorkDays >= 8)

      {

         System.out.println(“Number of days in work week is invlaid, please ensure the number is between 1 and 7”);

         System.out.print(“Please enter the number of days in the work week (Must be between 1 and 7 days): “);

         numWorkDays = in.nextInt();

      }

      //Initialize the arrays to store the Employees and Work Hours

      String[] employeeNames = new String[numEmployees];

      int[][] workedHours = new int[numEmployees][numWorkDays];

      //Input values into the arrays

      for(int i = 0; i < numEmployees; i++)

      {

         System.out.print(“Please enter the name of the employee: “);

         employeeNames[i] = in.next();

         System.out.println(“Please enter the number of hours worked each day”);

         for(int j = 0; j < numWorkDays; j++)

         {

            System.out.print(“Day ” + (j + 1) + “: “);

            workedHours[i][j] = in.nextInt();

         }

      }

      System.out.printf(“nn%-15s%12sn”, “Name”, “Hours”);

      System.out.println(“—————————-“);

      for(int i = 0; i < numEmployees; i++)

      {

         System.out.printf(“%-15s%12dn”, employeeNames[i], getHoursWorked(workedHours[i]));

      }   

   }

}

Here is a sample of the output for the program I have written:

Please enter the number of employees: 2

Please enter the number of days in the work week (Must be between 1 and 7 days): 5

Please enter the name of the employee: Chris

Please enter the number of hours worked each day

Day 1: 3

Day 2: 4

Day 3: 5

Day 4: 6

Day 5: 1

Please enter the name of the employee: Dorian

Please enter the number of hours worked each day

Day 1: 2

Day 2: 3

Day 3: 4

Day 4: 5

Day 5: 6

Name                 Hours

—————————-

Chris                   19

Dorian                  20

This is what I need it to be:

Please enter the number of employees: 2

Please enter the number of days in the work week (Must be between 1 and 7 days): 5

Please enter the name of the employee: Chris

Please enter the number of hours worked each day

Day 1: 3

Day 2: 4

Day 3: 5

Day 4: 6

Day 5: 1

Please enter the name of the employee: Dorian

Please enter the number of hours worked each day

Day 1: 2

Day 2: 3

Day 3: 4

Day 4: 5

Day 5: 6

Name                 Hours

—————————-

Dorian                  20

Chris                   19

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"