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.
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...
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:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F34215fe4-737d-4111-858a-1ca99d565feb%2F738605b5-0e15-4ef4-b37e-f1f1daa7e8d6%2F08b61x_processed.png&w=3840&q=75)
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F34215fe4-737d-4111-858a-1ca99d565feb%2F738605b5-0e15-4ef4-b37e-f1f1daa7e8d6%2Fea60mdo_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
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](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY