So I am in this class for Java programming and I think that I may be in way over my head... but, I want to give it a shot none the less.
The problem comes at me in this form,
Suppose the weekly hours for all employees are stored 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. Write a program that displays employees and thier total hours in decreasing order of the total hours.
Now, the example shown is just an array with the employee number and that employees hours in a seven day work week... I can get that, the problem I am having is the "display... in decreasing order of the total hours" part.... here is what i have so far:
import javax.swing.JOptionPane;
public class weeklyHoursSecondTry {
//**Main Method*//
public static void main(String[] args) {
int[][] hours = createHours();
//Display the days of the week
System.out.println(" S " + " M " + "T " + "W " + "H " + "F " + "Sa " );
for (int row = 0; row < hours.length; row++) {
System.out.print("Employee " );
for (int column = 0; column < hours.length; column++){
if (column < hours.length -1)
System.out.print(hours[row][column] + " ");
else if (column < hours.length)
System.out.println(hours[row][column]);
}
}
//Display the Matrix called hours
System.out.println("");
//Here is where the program totals the rows, but how do I store this total in matrix to be sorted?
for (int row = 0; row < hours[0].length; row++) {
int total = 0;
for (int column = 1; column < hours.length; column++)
total += hours[row][column];
System.out.println("Total hours for Employee " + row + " is " + total);
}
}
//Populate the array
public static int[][] createHours() {
int[][] hours = {
{0, 2, 4, 3, 4, 5, 8, 8}, //34
{1, 7, 3, 4, 3, 3, 4, 4}, //28
{2, 3, 3, 4, 3, 3, 2, 2}, //20
{3, 9, 3, 4, 7, 3, 4, 1}, //31
{4, 3, 5, 4, 3, 6, 3, 8}, //32
{5, 3, 4, 4, 6, 3, 4, 4}, //28
{6, 3, 7, 4, 8, 3, 8, 4}, //37
{7, 6, 3, 5, 9, 2, 7, 9}}; //41
return hours;
}
}
any suggestions on what I might do to get that to display in decreasing order or where I might look to learn how to do that? Thanks.
-x