Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By SurfMan

Thread: I need help with this!

  1. #1
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default I need help with this!

    Right, here is my problem. I keep getting this annoying error saying "Syntax error "throws" interface expected" and I am pretty dang sure that I have included one. Please point out my mistake and tell me exactly what is wrong and why? Thank you

    Java Code:
    	public static void main(String args[]) {
    throws IOException {
    
    	Scanner type = new Scanner(new File("C:\\report.txt"));
    	Scanner typeLw = new Scanner(System.in);
    	for (int enc = 1; enc <= 3; enc++); {
    		paySingleHardWorker(type);
    	}
    	for (int enc = 4; enc <= 6; enc++); {
    		
    	}
    	
    	
    }
    
    
    
    
    	
    		           
    		                    public static void paySingleHardWorker(Scanner type) {
    		                    HardWorker worker = new HardWorker();
    		                    
    		                    	worker.setName(type.nextLine());
    		                    	worker.setJob(type.nextLine());
    		                    	worker.setPay(type.nextDouble());
    		                    	worker.setpayRise(type.nextDouble());
    		                    	type.nextLine();
    		                    	type.nextLine();
    		                    	
    		                 System.out.println();
    		                    }
    		                    
    		                    public static void paySingleLazyWorker(Scanner typeLw, Scanner type) {
    		                    	LazyWorker worker = new LazyWorker();
    		                    	
    		                    	worker.setName(type.nextLine());
    		                    	worker.setJob(type.nextLine());
    		                    	worker.setPay(type.nextDouble());
    		                    	worker.setPayDeduction(type.nextDouble());
    		                    	type.nextLine();
    		                    	type.nextLine();
    		                    	
    		                    }
    		                    
    	
    		                    
    		
    	
    	}

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: I need help with this!

    If you tell us WHERE the error occurrs you think this would speed up the process?
    However why did you place your throws keyword at the location inside the method?

    Well it is a common mistake with your brackets I assume... put them like that, do a correct indention and you won't have such again:
    public static void main(...)
    {
    }
    Last edited by Sierra; 01-10-2013 at 09:11 PM.
    I like likes!

  3. #3
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Re: I need help with this!

    Thank you ever so much! Ah this bug has been annoying me! You were right, all I needed to do was remove the extra curly bracket. Now my line looks like this!: public static void main(String args[]) throws IOException
    {

    Thank you :)

  4. #4
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Re: I need help with this!

    You have a lot of whitespace. How you understand this amazed me.

  5. #5
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    106
    Rep Power
    0

    Default Re: I need help with this!

    do a correct indention and you won't have such again
    You have a lot of whitespace. How you understand this amazed me.
    In Eclipse, you can have Eclipse fix the indentation all at once for whole files by right-clicking on a window, choosing "Source" and then choosing "Correct indentation". It's important to have your indentation be correct to help you to understand your code.

  6. #6
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: I need help with this!

    I am not sure he is using Eclipse at all. ;)
    You also have the complete auto formatter there... once properly configured it is a great help with code from these forums XD
    ... CTRL+SHIFT+F ^^
    I like likes!

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,086
    Rep Power
    4

    Default Re: I need help with this!

    The next bug you will run into is that your loops don't appear to be working. That is because of the ; behind the for statement.

    Wrong:
    Java Code:
    for (int enc = 1; enc <= 3; enc++); {
       System.out.println("This prints only once);
    }
    The Java tutorial says that if you have a single statement to execute in the for statement, you can leave out the curly braces { }. For example:
    Java Code:
    for (int enc = 1; enc <= 3; enc++)
       System.out.println("This prints three times);
    You can write the same code WITH braces, looking like this:
    Java Code:
    for (int enc = 1; enc <= 3; enc++) {
       System.out.println("This prints three times);
    }
    But, if you put a semicolon behind a for statement, like in your case, this is what the compiler sees:
    Java Code:
    for (int enc = 1; enc <= 3; enc++)
         ; 
    {
       System.out.println("This prints only once);
    }
    You have executed an empty line three times (In fact, I think the compiler will remove the useless loop alltogether).
    The { } in the last example is just a block of code, which is valid in Java.
    Sierra likes this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •