Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 19 of 19

Thread: weekly hours for each employee

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:
    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());
    				}
    		}
     
    		}
     
     
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: weekly hours for each employee

    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

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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:
    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.

  5. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: weekly hours for each employee

    i am using the eclipse compiler and all the braces on my end line up.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: weekly hours for each employee

    Fix your post #1 so they all line up. See my post#2

  7. #7
    Junior Member
    Join Date
    Sep 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: weekly hours for each employee

    u want me to repost my entire #1 so that all the braces line up?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.

  9. #9
    Junior Member
    Join Date
    Sep 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: weekly hours for each employee

    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?
    Last edited by sircamolate; September 1st, 2011 at 02:20 PM.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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:
      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

  11. #11
    Junior Member
    Join Date
    Sep 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: weekly hours for each employee

    See post #10 for an example

  13. #13
    Junior Member
    Join Date
    Sep 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.
    are u asking for pseudocode?

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.

  15. #15
    Junior Member
    Join Date
    Sep 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: weekly hours for each employee

    Edit your post
    Use the Go Advanced button on the lower right.
    Select all your code.
    Press the #icon button in the upper right
    Press Preview Post
    Then press Submit

  17. #17
    Junior Member
    Join Date
    Sep 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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

  19. #19
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default 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.
    Improving the world one idiot at a time!

Similar Threads

  1. Program to read & write the Employee Records
    By arvindk.vij in forum Member Introductions
    Replies: 1
    Last Post: February 11th, 2011, 01:19 AM
  2. Program to read & write the Employee Records
    By arvindk.vij in forum Java Theory & Questions
    Replies: 1
    Last Post: February 11th, 2011, 01:19 AM
  3. Hours worked help
    By glacier23 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 11th, 2010, 12:58 AM
  4. need in few hours help me
    By erinbasim in forum Java Theory & Questions
    Replies: 3
    Last Post: February 2nd, 2010, 06:39 PM
  5. project needed in two hours
    By erinbasim in forum Project Collaboration
    Replies: 1
    Last Post: February 2nd, 2010, 04:21 AM