Question

Course: CMSC 200 (Computer Programming - Java)

CMSC200 HOMEWORK 9 Graded against 3 test cases totaling 30 points Description: Suppose the weekly hours for all employees are stored in a two-dimensional array. Each row records an employees seven-day work hours with seven columns. For example, the following array stores the work hours for eight employees. Write a program that displays employees and their total hours in decreasing order of the total hours. See sample output below Required Method public static void sort (int[][] workHours) None. All testing is done through the required method which accepts a populated 2-dim INTEGER array. Note: In the example below, only the numeric values would be contained in the array Input Output Employee and total hours in decreasing order EXAMPLE When passing in the follow array, the output is display below Array: Su Mon Tue Wen Thurs Fr Sat Employee024 Employee 73 Employee 233 Employee 3 93 Employee 4 35 Employee 534 Employee 637 Employee7 63 4 4 4 3 41 4 Output Employee 7: 41 Employee 6: 37 Employee 0: 34 Employee 4: 32 Employee 3: 31 Employee 1: 28 Employee 5: 28 Employee 2: 20 Packaging: Fully qualified class names are listed below: (Note: the bold is the class itself) edu.ben.homeworks.homework9.Homework Submission: Submit your code, as always, to both SVN and WebCAT. Benedictine University

0 0
Add a comment Improve this question Transcribed image text
Answer #1
/*
Suppose the weekly hours for all employees are stored in a two-dimensional array.
Each row records an employ-ee’s seven-day work hours with seven columns.
For example, the following array stores the work hours for eight employees.
Write a program that displays employees and their total hours in decreasing
order of the total hours
*/

public class Exercise_08_03

{

public static void main(String[] args)

{

int[][] employeeHours =
{{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[][] totalHoursPerEmployee = new int[7][1];
int[] totalHoursPerEmployee = sumEmployeeHours(employeeHours);
int[] indexList = new int[totalHoursPerEmployee.length];
sortWhileKeepingIndices(totalHoursPerEmployee, indexList);
for (int i = 0; i < totalHoursPerEmployee.length; i++) {
System.out.printf("Employee %s worked %d hours%n", indexList[i], totalHoursPerEmployee[i]);
}
System.out.println(java.util.Arrays.toString(indexList));
}

public static int[] sumEmployeeHours(int[][] hours)

{

int[] totalHoursPerEmployee = new int[hours.length];

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

{

int sum = 0;

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

{

sum += hours[i][j];
}
totalHoursPerEmployee[i] = sum;
}
return totalHoursPerEmployee;
}

static void sortWhileKeepingIndices(int[] totalHours, int[] indexList)

{

//fill indexList

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

{

indexList[i] = i;
}

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

{

int currentMax = totalHours[i];
int currentMaxIndex = i;

for (int j = i + 1; j < totalHours.length; j++)

{

if (currentMax < totalHours[j])

{

currentMax = totalHours[j];
currentMaxIndex = j;
}
}
if (currentMaxIndex != i) {
totalHours[currentMaxIndex] = totalHours[i];
totalHours[i] = currentMax;
int temp = indexList[currentMaxIndex];
indexList[currentMaxIndex] = indexList[i];
indexList[i] = temp;
}
System.out.println(java.util.Arrays.toString(indexList) + " - " + java.util.Arrays.toString(totalHours));
}
}
}
Add a comment
Know the answer?
Add Answer to:
Course: CMSC 200 (Computer Programming - Java) CMSC200 HOMEWORK 9 Graded against 3 test cases totaling...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • employees.txt Instructions You will be using Eclipse for all assignments in this course. You can download...

    employees.txt Instructions You will be using Eclipse for all assignments in this course. You can download Eclipse from the Virtual Desktop. Please write a Java program that follows the instructions below. There are two files to download. AvaCam Inc. is interested in the electronic computation of their payroll. They have reached out, and you have agreed to write a program to help them. They have sent you the file employees.txt (right-click to download the file). Store this file in the...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

  • Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What...

    Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What This Assignment Is About? Classes (methods and attributes) • Objects Arrays of Primitive Values Arrays of Objects Recursion for and if Statements Selection Sort    Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use upper case for constants. • Use title case (first letter is upper case) for classes. Use lower case with uppercase...

  • Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The...

    Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The owners of the Annan Supermarket would like to have a program that computes the weekly gross pay of their employees. The user will enter an employee’s first name, last name, the hourly rate of pay, and the number of hours worked for the week. In addition, Annan Supermarkets would like the program to compute the employee’s net pay and overtime pay. Overtime hours, any...

  • Solve it for java Question Remember: You will need to read this assignment many times to...

    Solve it for java Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...

  • Java please At this point in your life most of you have or have had a...

    Java please At this point in your life most of you have or have had a job. One of the aspects of a job is dealing with taxes. Benjamin Franklin said “in this world nothing can be said to be certain, except death and taxes.” There are many types of taxes. Some of the most familiar taxes are state sales tax, federal and state income tax and local property tax. Write a program that will compute and print the federal,...

  • Description: A program is needed for a third-party payroll clearinghouse that supports the following: Calculate employee...

    Description: A program is needed for a third-party payroll clearinghouse that supports the following: Calculate employee pay feature Company total pay feature The employee and company totals are stored in a text file for each individual company. 1. Create the following “input.txt” file. Each record consists of a first name, last name, employee ID, company name, hours worked, and pay rate per hour. Maria    Brown 10 Intel   42.75 39.0 Jeffrey Jackson 20 Boeing   38.0 32.5 Bernard Smith 30 Douglas   25.0...

  • ELEC 1520 Homework - Integer Operations, Selection Statements Instructions Write C++ programs to solve the following...

    ELEC 1520 Homework - Integer Operations, Selection Statements Instructions Write C++ programs to solve the following two problems. Upload your source code files to Canvas. The file names must be of the form coins_your_name.cpp and bonus_your_name.cpp for problems 1 and 2, respectively. Substitute your first and last name for "your_name" in the file name. Problem Statements 1. Given a value V in cents, you need to make change using a minimum number of coins. Assume you have an infinite supply...

  • URGENT I have 3 hours for Submit this Homework so you can share yout codes with...

    URGENT I have 3 hours for Submit this Homework so you can share yout codes with me in 150mins Preliminary Notes: You have 4 hours to submit your solution. No late submission is accepted. Do not leave your submission to the last minute. You are not allowed to copy any code from anywhere. Your code will be checked by a software for similarity. Implement the code on your own and never share it with someone else. A test code is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT