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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Need help with writing 2d array program. Attatching the problem with the images.

**Computing Weekly Work Hours for Employees**

---

**Objective:**
Develop a program that computes and displays the weekly work hours for each employee. The weekly hours for all employees are stored in a two-dimensional array where each row corresponds to a seven-day work week for a different employee. This program also displays employees and their total work hours in decreasing order.

**Example Array:**

|        | Su | M | T | W | R | F | Sa |
|--------|----|---|---|---|---|---|----|
| Employee0 | 2  | 4 | 3 | 4 | 5 | 8 | 8  |
| Employee1 | 7  | 3 | 4 | 3 | 3 | 4 | 4  |
| Employee2 | 9  | 3 | 4 | 7 | 3 | 4 | 1  |
| Employee3 | 3  | 3 | 4 | 3 | 3 | 2 | 2  |
| Employee4 | 9  | 3 | 4 | 7 | 3 | 4 | 1  |
| Employee5 | 3  | 3 | 4 | 3 | 5 | 4 | 2  |
| Employee6 | 3  | 3 | 4 | 3 | 3 | 4 | 2  |
| Employee7 | 6  | 3 | 5 | 9 | 2 | 7 | 9  |

**Requirements:**

1. **Compute Total Hours:**
   Design a method that accepts the 2-D array of weekly hours for all employees as an input parameter. Calculate the sum of the total hours of all employees and return the total hour results in an array.

2. **Sort Total Hours:**
   Design a method to sort the array returned by the method in Requirement 1 using selection sort in decreasing order.
   - **Important:** During sorting, keep track of which employee corresponds to how many work hours. Store the employee information in an array and return it as a result of the sorting method.

3. **Display Results:**
   Design a method to display the results of employees and their total work hours in decreasing order. Below is a sample output for the given example:
  
   ```
   Employee7: 41 hours
   Employee6:
Transcribed Image Text:**Computing Weekly Work Hours for Employees** --- **Objective:** Develop a program that computes and displays the weekly work hours for each employee. The weekly hours for all employees are stored in a two-dimensional array where each row corresponds to a seven-day work week for a different employee. This program also displays employees and their total work hours in decreasing order. **Example Array:** | | Su | M | T | W | R | F | Sa | |--------|----|---|---|---|---|---|----| | Employee0 | 2 | 4 | 3 | 4 | 5 | 8 | 8 | | Employee1 | 7 | 3 | 4 | 3 | 3 | 4 | 4 | | Employee2 | 9 | 3 | 4 | 7 | 3 | 4 | 1 | | Employee3 | 3 | 3 | 4 | 3 | 3 | 2 | 2 | | Employee4 | 9 | 3 | 4 | 7 | 3 | 4 | 1 | | Employee5 | 3 | 3 | 4 | 3 | 5 | 4 | 2 | | Employee6 | 3 | 3 | 4 | 3 | 3 | 4 | 2 | | Employee7 | 6 | 3 | 5 | 9 | 2 | 7 | 9 | **Requirements:** 1. **Compute Total Hours:** Design a method that accepts the 2-D array of weekly hours for all employees as an input parameter. Calculate the sum of the total hours of all employees and return the total hour results in an array. 2. **Sort Total Hours:** Design a method to sort the array returned by the method in Requirement 1 using selection sort in decreasing order. - **Important:** During sorting, keep track of which employee corresponds to how many work hours. Store the employee information in an array and return it as a result of the sorting method. 3. **Display Results:** Design a method to display the results of employees and their total work hours in decreasing order. Below is a sample output for the given example: ``` Employee7: 41 hours Employee6:
### Homework Example: Displaying and Sorting Work Hours of Employees

In this example, we have a Java program designed to calculate and display the total hours worked by employees during the week. The employee work hours are stored in a 2D array, and the program is required to sum these hours, sort them in decreasing order, and display them.

Here is the complete code along with placeholders for the missing parts that you need to complete.

```java
package homework;

public class HW8 {

    public static void main(String[] args) {
        int[][] workHours = {
            {2, 4, 3, 4, 5, 8, 8},
            {7, 3, 4, 3, 3, 4, 4},
            {3, 3, 4, 3, 3, 2, 2},
            {9, 3, 4, 7, 3, 4, 1},
            {3, 5, 4, 3, 6, 3, 8},
            {3, 4, 4, 6, 3, 4, 4},
            {3, 7, 4, 8, 3, 8, 4},
            {6, 3, 5, 9, 2, 7, 9}
        };

        int[] sumArray = calculateSum(workHours);
        int[] indexArray = decreasingSort(sumArray);
        displayArray(indexArray, sumArray);
    }

    public static int[] calculateSum(int[][] array) {
        // Please write your code here
    }

    public static int[] decreasingSort(int[] array) {
        // Please write your code here
    }

    public static void displayArray(int[] indexArray, int[] array) {
        /*
        Please write your code here
        */
        System.out.println("Employee" + indexArray[i] + ": " + array[i] + " hours");
    }
}
```

### Explanation of Key Functions:

1. **calculateSum()**:
    - **Input**: A 2D array representing the work hours of each employee for each day of the week.
    - **Output**: A 1D array where each element is the total hours worked by each employee.
    - **Function**: This function will iterate over the
Transcribed Image Text:### Homework Example: Displaying and Sorting Work Hours of Employees In this example, we have a Java program designed to calculate and display the total hours worked by employees during the week. The employee work hours are stored in a 2D array, and the program is required to sum these hours, sort them in decreasing order, and display them. Here is the complete code along with placeholders for the missing parts that you need to complete. ```java package homework; public class HW8 { public static void main(String[] args) { int[][] workHours = { {2, 4, 3, 4, 5, 8, 8}, {7, 3, 4, 3, 3, 4, 4}, {3, 3, 4, 3, 3, 2, 2}, {9, 3, 4, 7, 3, 4, 1}, {3, 5, 4, 3, 6, 3, 8}, {3, 4, 4, 6, 3, 4, 4}, {3, 7, 4, 8, 3, 8, 4}, {6, 3, 5, 9, 2, 7, 9} }; int[] sumArray = calculateSum(workHours); int[] indexArray = decreasingSort(sumArray); displayArray(indexArray, sumArray); } public static int[] calculateSum(int[][] array) { // Please write your code here } public static int[] decreasingSort(int[] array) { // Please write your code here } public static void displayArray(int[] indexArray, int[] array) { /* Please write your code here */ System.out.println("Employee" + indexArray[i] + ": " + array[i] + " hours"); } } ``` ### Explanation of Key Functions: 1. **calculateSum()**: - **Input**: A 2D array representing the work hours of each employee for each day of the week. - **Output**: A 1D array where each element is the total hours worked by each employee. - **Function**: This function will iterate over the
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY