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.

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
Employeel 7
3
4
3
3
4
4
Employee2 3
3
4
3
3
2
2
Employee3 9
3
4
3
4
1
Employee4 3
4
3
6
3
8
Employee5 3
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. The
sample output for the above example is as follows:
C:\WINDOWS\system32\cmd.exe
Employee?: 41 hours
Employee6: 37 hours
Employee: 34 hours
Employee 4: 32 hours
Employee3: 31 hours
Employee5: 28 hours
Employee1: 28 hours
Employee2: 20 hours
Press any key to continue
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.
5
4
7
|L
Transcribed Image Text: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 Employeel 7 3 4 3 3 4 4 Employee2 3 3 4 3 3 2 2 Employee3 9 3 4 3 4 1 Employee4 3 4 3 6 3 8 Employee5 3 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. The sample output for the above example is as follows: C:\WINDOWS\system32\cmd.exe Employee?: 41 hours Employee6: 37 hours Employee: 34 hours Employee 4: 32 hours Employee3: 31 hours Employee5: 28 hours Employee1: 28 hours Employee2: 20 hours Press any key to continue 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. 5 4 7 |L
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, 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 display Array (int[] indexArray, int[] array) {
/*Please write your code here*/
System.out.println("Employee" + indexArray[i] + + array[i] +
"hours");
}
Finally, your code's formatting should look exactly like the output mentioned below and should be able to
run/compile.
Employee7: 41 hours
Employee6: 37 hours
Employeee: 34 hours
Employee4: 32 hours
Employee3: 31 hours
Employees: 28 hours
Employee1: 28 hours
Employee2: 20 hours
Transcribed Image Text: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, 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 display Array (int[] indexArray, int[] array) { /*Please write your code here*/ System.out.println("Employee" + indexArray[i] + + array[i] + "hours"); } Finally, your code's formatting should look exactly like the output mentioned below and should be able to run/compile. Employee7: 41 hours Employee6: 37 hours Employeee: 34 hours Employee4: 32 hours Employee3: 31 hours Employees: 28 hours Employee1: 28 hours Employee2: 20 hours
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
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