weekly hours for each employee

• September 1st, 2011, 11:03 AM
sircamolate
weekly hours for each employee
I am working on writing a code that allows me to display the employees and their total hours in decreasing order of the total hours. i have the displaying of the array and the summing of the array down but i can't get the sorting algorithm to work. I was hoping that i could get someone to help me with it. ill take answers or ill even take help comments. but please someone help me, this sorting stuff is pissing me off. :) (When i compile i get 1 error message and it is on line 45 or where it says public void hours().)
Here is what i have so far:
Code Java:

```import java.util.Arrays; import java.util.Collections;   public class Employee { public static void main(String[] args) {     int [] [] hours = { {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 [][] totalhours = new int[8][7];   // Display the array for (int row = 0; row < 8; row++) { for (int col = 0; col < 7; col++) System.out.print(hours[row][col] + " "); System.out.println();   }   // sum rows of the array int total;   for (int row = 0; row < hours.length; row++) { total = 0; for (int col = 0; col < hours[row].length; col++) total += hours[row][col];   System.out.println(" Total of row " + row + " is " + total); totalhours [row][0] = total;   }   // sort the contents of the array in descending order public void hours() { int h;   Integer[][] hours = new Integer[] { new Integer (34), new Integer (28), new Integer (20), new Integer (31), new Integer (32), new Integer (28), new Integer (37), new Integer (41) };   Arrays.sort(arrayToSort, Collections.reverseOrder());   for (Integer h : hours) { System.out.println(h.intValue()); } }   }       }```
• September 1st, 2011, 11:35 AM
Norm
Re: weekly hours for each employee
Quote:

when i compile i get 1 error message and it is on line 45 or where it says public void hours().)
What is the full text of the error message. Please copy and paste it here.

Please edit you code and wrap it in code tags to preserve the formatting. Use the #icon or
see: BB Code List - Java Programming Forums
• September 1st, 2011, 12:28 PM
sircamolate
Re: weekly hours for each employee
here is the error message i get:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "void", @ expected
Syntax error, insert "enum Identifier" to complete EnumHeaderName
Syntax error, insert "EnumBody" to complete BlockStatement

at Employee.main(Employee.java:43)
• September 1st, 2011, 12:45 PM
Norm
Re: weekly hours for each employee
Those are weird compiler errors. What compiler are you using?
Here is what the javac command outputs for me:
Code :

```TestSorts.java:138: cannot find symbol symbol : variable var location: class TestSorts var = 2; ^```

I can't easily read you code because it has not been properly formatted. The ending } should be in alignment below the statement where the starting { is. Statements within the {} should be indented at least 3 spaces.

Check that each of your method's beginning { and ending } are paired correctly.
• September 1st, 2011, 12:59 PM
sircamolate
Re: weekly hours for each employee
i am using the eclipse compiler and all the braces on my end line up.
• September 1st, 2011, 01:01 PM
Norm
Re: weekly hours for each employee
Fix your post #1 so they all line up. See my post#2
• September 1st, 2011, 02:23 PM
sircamolate
Re: weekly hours for each employee
u want me to repost my entire #1 so that all the braces line up?
• September 1st, 2011, 02:32 PM
Norm
Re: weekly hours for each employee
If you want help with your problem, you need to post properly formatted code. Especially when it looks like the problem is with mismatched {} or misplaced methods or other code.

You don't need to post a second copy. You could edit the Post#1 and fix it there.
• September 1st, 2011, 02:41 PM
sircamolate
Re: weekly hours for each employee
Code :

```import java.util.Arrays; import java.util.Collections;   public class Employee { public static void main(String[] args) {     int [] [] hours = { {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 [][] totalhours = new int[8][7];   // Display the array   for (int row = 0; row < 8; row++) { for (int col = 0; col < 7; col++)   System.out.print(hours[row][col] + " "); System.out.println();   }   // sum rows of the array int total;   for (int row = 0; row < hours.length; row++) {   total = 0; for (int col = 0; col < hours[row].length; col++) total += hours[row][col];   System.out.println(" Total of row " + row + " is " + total);   totalhours [row][0] = total;   }   // sort the contents of the array in descending order public void hours() {   int h;   Integer[][] hours = new Integer[] { new Integer (34), new Integer (28), new Integer (20), new Integer (31), new Integer (32), new Integer (28), new Integer (37), new Integer (41) };   Arrays.sort(arrayToSort, Collections.reverseOrder());   for (Integer h : hours) {   System.out.println(h.intValue()); } }   }   }```

hows that?
• September 1st, 2011, 02:44 PM
Norm
Re: weekly hours for each employee
Did you look at it after you posted it? Do a Preview before posting to see if the code is formatted.
It looks the same as post#1. It needs to be fixed!
You need to wrap the code in code tags. Press the Go Advanced button and use the #icon or
see this: BB Code List - Java Programming Forums

It should look like this:
Code :

``` class WindowCloser extends WindowAdapter { public WindowCloser(){}   @Override // method does not override or implement a method from a supertype public void windowClosing(WindowEvent wE) { System.exit(0); } } //end class```
• September 1st, 2011, 02:47 PM
sircamolate
Re: weekly hours for each employee
im sry man, i lookd at that bb code list deal and i didnt really understand wat u meant. could u post a quick lil example for me so i know wat u need done. the program doesnt have to b mine. i just need an example to go off of. i do better wit examples. if its not to much to ask that it.
• September 1st, 2011, 02:48 PM
Norm
Re: weekly hours for each employee
See post #10 for an example
• September 1st, 2011, 02:55 PM
sircamolate
Re: weekly hours for each employee
im really not tryin to make yo life difficult but i cnt see the diff. between the code i have n ur code. it looks properly formatted to me.
• September 1st, 2011, 02:59 PM
Norm
Re: weekly hours for each employee
The code you posted is not indented at each level of nesting within a pair of {}s.
When looking at the code you should be able to go up in a column from a } to find the line with the beginning {.

Look at the code in post#10. Start at a } and going up in the column you find the line with the beginning {

In your code it is not possible.
• September 1st, 2011, 03:11 PM
sircamolate
Re: weekly hours for each employee
i tried editing it so that it is easier to read for you and everytime i go to preview post it still looks the same as it does meow. idk wat to do. :(
• September 1st, 2011, 03:17 PM
Norm
Re: weekly hours for each employee
Use the Go Advanced button on the lower right.
Press the #icon button in the upper right
Press Preview Post
Then press Submit
• September 1st, 2011, 03:21 PM
sircamolate
Re: weekly hours for each employee
i think i got it!!! :) take another look at the second post i did of my code and lemme know if it wrks.
• September 1st, 2011, 03:26 PM
Norm
Re: weekly hours for each employee
Yes that looks somewhat better.
Have you checked that the matching {}s for each method do not include other methods?
To help detect this go to each ending } and add a comment saying its the end of ...
where ... is the method name or for loop or ....
For example:
} // end of aMethod()
or
} // end of for(i)
or
} // end of class Employee

When they are all labelled you should be able to see if there are any nested methods
• September 1st, 2011, 07:09 PM
Junky
Re: weekly hours for each employee
For me it looks like your hours method is inside the main method but since your code is poorly formatted it is hard to tell.