Sign In
Not register? Register Now!
Pages:
1 page/≈275 words
Sources:
No Sources
Level:
APA
Subject:
IT & Computer Science
Type:
Other (Not Listed)
Language:
English (U.S.)
Document:
MS Word
Date:
Total cost:
$ 5.4
Topic:

Creating a Two-Dimension Array Using Java (Other (Not Listed) Sample)

Instructions:
Type of paper Essay (Any Type) Subject Computer Science Number of pages 1 Format of citation Other Number of cited resources 0 Type of service Writing CSCI 1301 Homework #9 Due date: November 5, 2023 (Sunday), 11:59pm 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 Employee1 7 3 4 3 3 4 4 Employee2 3 3 4 3 3 2 2 Employee3 9 3 4 7 3 4 1 Employee4 3 5 4 3 6 3 8 Employee5 3 4 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: 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. Grading: This assignment is worth 100 points. If your program has compilation or run time errors, you will receive 0 point. Grade criteria Maximum points Correct result and output Proper implementation of all features specified in the program 80 Proper style and documentation * 20 * The requirement of proper style and documentation can be found in “Expanded Guidelines on Programming Style and Documentation” document in the “Course Info” module in folio. How to hand in the assignment When you finish your assignment, you will upload (submit) it to Gradescope. I remind you that if you do not submit the assignment before the due date, you will not be able to submit it. 1. Complete the assignment and name it HW9. 2. Return to the Gradescope to submit the .java file for this assignment. 3. Browse for the HW9.java file that you have on your computer and select it so that it uploads to the assignment area. 4. Click “Upload”. * For this assignment, please name your class file as “HW9” package homework; public class HW9 { 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"); } * 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 Employee0: 34 hours Employee4: 32 hours Employee3: 31 hours Employee5: 28 hours Employee1: 28 hours Employee2: 20 hours source..
Content:
Two-dimensional Array Employee Program. Name Date Course Part 1 The following is the program that calculates the weekly hours for each employee, stores them in a two-dimensional array, and displays the employees and their total hours in decreasing order. Code package homework; import java.util.Arrays; public class HW9 { public static void main(String[] args) { int[][] weekHours = { {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} }; String[] employeeNames = {"Employee0", "Employee1", "Employee2", "Employee3", "Employee4", "Employee5", "Employee6", "Employee7"}; int[] totalHours = calculateTotalHours(weekHours); sortEmployeesByTotalHours(employeeNames, totalHours); // The decreasing order of the employees and their total hours System.out.println("Employee\tTotal Hours"); for (int i = 0; i < employeeNames.length; i++) { System.out.println(employeeNames[i] + "\t" + totalHours[i]); } } public static int[] calculateTotalHours(int[][] hoursArray) { int[] totalHours = new int[hoursArray.length]; for (int i = 0; i < hoursArray.length; i++) { for (int j = 0; j < hoursArray[i].length; j++) { totalHours[i] += hoursArray[i][j]; } } return totalHours; } public static void sortEmployeesByTotalHours(String[] employeeNames, int[] totalHours) { for (int i = 0; i < totalHours.length - 1; i++) { for (int j = i + 1; j < totalHours.length; j++) { if (totalHours[i] < totalHours[j]) { int tempHours = totalHours[i]; totalHours[i] = totalHours[j]; totalHours[j] = tempHours; String tempName = employeeNames[i]; employeeNames[i] = employeeNames[j]; employeeNames[j] = tempName; } } } } } Part 2 The following code provides a technique for determining the total number of hours and arranging workers based on their overall work hours through the employment of the selection sort algorithm while also monitoring employee details. This software computes each worker's cumulative working time, sorts them by their respective total hours worked using the descending order selection sorting method, and preserves all employee-related data in an array named "employeeNames." Code package homework; import java.util.Arrays; public class HW9 { public static void main(String[] args) { int[][] weekHours = { {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} }; String[] employeeNames = {"Employee0", "Employee1", "Employee2", "Employee3", "Employee4", "Employee5", "Employee6", "Employee7"}; int[] totalHours = calculateTotalHours(weekHours); // Arrange the employees by total hours in descending order and get the sorted employee names String[] sortedEmployeeNames = sortEmployeesByTotalHours(employeeNames, totalHours); //The employees and their total hours in decreasing order System.out.println("Employee\tTotal Hours"); for (int i = 0; i < sortedEmployeeNames.length; i++) { int employeeIndex = Integer.parseInt(sortedEmployeeNames[i].substring(8)); // Extract the employee index System.out.println(sortedEmployeeNames[i] + "\t" + totalHours[employeeIndex]); } } public static int[] calculateTotalHours(int[][] hoursArray) { int[] totalHours = new int[hoursArray.length]; for (int i = 0; i < hoursArray.length; i++) { for (int j = 0; j < hoursArray[i].length; j++) { totalHours[i] += hoursArray[i][j]; } } return totalHours; } public static String[] sortEmployeesByTotalHours(String[] employeeNames, int[] totalHours) { int n = totalHours.length; for (int i = 0; i < n - 1; i++) { int maxIndex = i; for (int j = i + 1; j < n; j++) { if (totalHours[j] > totalHours[maxIndex]) { maxIndex = j; } } // employee names String tempName = employeeNames[i]; employeeNames[i] = employeeNames[maxIndex]; employeeNames[maxIndex] = tempName; // total hours int tempHours = totalHours[i]; totalHours[i] = totalHours[maxIndex]; totalHours[maxIndex] = tempHours; } return employeeNames; } } Part 3 The following is the code where the main method of this program employs shorthand initialization to initialize a 2-D array containing the weekly working hours of all employees. It then proceeds to calculate their total hours, sort them in desce...
Get the Whole Paper!
Not exactly what you need?
Do you need a custom essay? Order right now:

Other Topics:

  • PCI DSS and its Specific Requirements for Applications
    Description: PCI DSS and its Specific Requirements for Applications IT & Computer Science Other (Not Listed)...
    1 page/≈275 words| 2 Sources | APA | IT & Computer Science | Other (Not Listed) |
  • Report on Pittsburgh Property Sales Data Analysis
    Description: Report on Pittsburgh Property Sales Data Analysis IT & Computer Science Other (Not Listed)...
    9 pages/≈2475 words| 7 Sources | APA | IT & Computer Science | Other (Not Listed) |
  • Feature Selection With Python
    Description: Question One The shape of the dataset is 800 rows and 258 columns. The number of features is 256, and the target variable (gnd) feature totals 257. Question Two. The dataset is split into training and validation testing data to achieve high accuracy of the logistic regression model. The model attained ...
    1 page/≈550 words| No Sources | APA | IT & Computer Science | Other (Not Listed) |
Need a Custom Essay Written?
First time 15% Discount!