Results 1 to 6 of 6
  1. #1
    jacjacjac is offline Member
    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Default <identifier expected> error

    Now I am getting another error. I am trying to have it return so that when the user enters an invalid number they can enter another number (correct number). I took away public static void main(String[] args) because the void wasn't letting it return. This is the error I get:
    Java Code:
    payRoll.java:7: error: <identifier> expected
    	public static boolean status(status)
    	                                   ^
    1 error
    This is the updated code:
    Java Code:
    import java.util.Scanner;
    import java.util.Random;
    
    public class payRoll
    {
    	
    	public static boolean status(status)
    	{
    	int payRate;
    	int hoursWorked;
    	boolean status;
    	Scanner keyboard = new Scanner(System.in);
    	
    		{
    			do
    			{
    			System.out.println("Enter the hourly pay rate");
    			payRate = keyboard.nextInt();
    			}
    			while (payRate>7.5 && payRate<18.25);
    			if(payRate>7.5 && payRate<18.25)
    				status = true;
    			else
    				status = false;
    				System.out.println("You have entered an invalid number");
    			return status;
    		}
    			
    			{
    			do
    			{
    			System.out.println("Enter the number of hours worked");
    			hoursWorked = keyboard.nextInt();
    			}
    			while  (hoursWorked>0 && hoursWorked<40);
    			if(hoursWorked>0 && hoursWorked<40)
    				status = true;
    			else
    				status = false;
    				System.out.println("You have entered an invalid number");
    				return status;
    			}
    		
    		
    	}
    }

  2. #2
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: <identifier expected> error

    You need to specify a data type for the status method.

  3. #3
    jacjacjac is offline Member
    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Default Re: <identifier expected> error

    Quote Originally Posted by PhQ View Post
    You need to specify a data type for the status method.
    Okay so I fixed that, I got it to compile and now I get No main methods, applets, or MIDlets found in file. I know that is because there is no main, but when I do put a main, I get so many errors. Arggggg. Any help here to get this to run???

  4. #4
    Abizzar is offline Member
    Join Date
    Oct 2012
    Location
    Georgia
    Posts
    7
    Rep Power
    0

    Default Re: <identifier expected> error

    Try this. I basically just turned the payrate variable into a double because you are using decimals.

    Java Code:
    import java.util.Scanner;
    import java.util.Random;
     
    public class payRoll
    {
         
        public static void main(String[] args)
        {
        double payRate;
        int hoursWorked;
        boolean status;
        Scanner keyboard = new Scanner(System.in);
         
           {
                do
                {
                System.out.println("Enter the hourly pay rate");
                payRate = keyboard.nextDouble();
                }
                while (payRate>7.5 && payRate<18.25);
                if(payRate>7.5 && payRate<18.25)
                    status = true;
                    
                else
                    status = false;
                    System.out.println("You have entered an invalid number");
                
            }
           {
                do
                {
                System.out.println("Enter the number of hours worked");
                hoursWorked = keyboard.nextInt();
                }
                while  (hoursWorked>0 && hoursWorked<40);
                if(hoursWorked>0 && hoursWorked<40)
                    status = true;
                    
                else
                    status = false;
                    System.out.println("You have entered an invalid number");
                }
            }
        }

  5. #5
    penguinCoder is offline Member
    Join Date
    Oct 2012
    Location
    Tempe, Arizona
    Posts
    77
    Blog Entries
    12
    Rep Power
    0

    Default Re: <identifier expected> error

    It is good practice to inform the user if they do something wrong if you are going to repeat something until they get it right. You should insert a:
    Java Code:
    do{
      System.out.println("Enter the hourly pay rate");
      payRate = keyboard.nextDouble();
    
      if(payRate<7.5 && payRate>18.25)
        System.out.println("Invalid! Enter between 7.5 - 18.25 only!");
    }while (payRate>7.5 && payRate<18.25);
    That is just an opinion thing though.

    Looking at your code, it seems like you double check each number the user enters.. If you are going to loop something until the variable is between 1-10, you don't then have to say 'if(variable is between 1-10) Do this". You have already made sure the number is between 1-10. You do this for both the payRate and the hoursWorked. It seems a bit redundant.

    If you trimmed the fat off of this program, and added the extra lines I suggested, it would be about 25 lines long..
    Last edited by penguinCoder; 10-14-2012 at 02:32 AM.

  6. #6
    penguinCoder is offline Member
    Join Date
    Oct 2012
    Location
    Tempe, Arizona
    Posts
    77
    Blog Entries
    12
    Rep Power
    0

    Default Re: <identifier expected> error

    Just another FYI thing. I don't know if you wanted the:
    Java Code:
                else
                    status = false;
                    System.out.println("You have entered an invalid number");
    to be all part of the else statement or not; but it is not. If there is more then one statement involved after the 'if' or the 'else', then you must use brackets. The portion "System.out.println("You have entered an invalid number");" is going to print regardless of what is true or false in the 'if' statement, as it is not going to be registered as part of the 'if' statement. It will see it as a separate piece of the code.

Similar Threads

  1. Error: Identifier Expected
    By vickyv200 in forum New To Java
    Replies: 9
    Last Post: 08-31-2012, 10:05 AM
  2. identifier expected error
    By Java Learner in forum New To Java
    Replies: 1
    Last Post: 04-27-2010, 08:13 PM
  3. getting identifier expected error . help me !
    By victorkeath in forum New To Java
    Replies: 3
    Last Post: 11-07-2008, 05:49 PM
  4. Identifier expected error
    By vasu18 in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 05:49 PM
  5. Error: <identifier> expected
    By barney in forum AWT / Swing
    Replies: 2
    Last Post: 07-31-2007, 07:38 AM

Posting Permissions

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