ZEFRANK.COM - message board  

Go Back   ZEFRANK.COM - message board > FAST CHAT
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 10-24-2006, 04:32 PM   #1
xerocs
Lurk
 
xerocs's Avatar
 
Join Date: Jan 2003
Location: Rapid City, SoDak
Posts: 1,341
Java Array help needed

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
xerocs is offline   Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -3. The time now is 12:04 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.