10 Replies - 1301 Views - Last Post: 04 February 2012 - 11:02 PM Rate Topic: -----

#1 tray2475   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 11-January 12

Compile errors for an employee payroll program.

Posted 04 February 2012 - 09:16 PM

Second wee of Java and I am having a little problem getting this to compile correctly. I am looking for a little advice.

First here is my code:

// PayrollProgram.java
// Java application that calculates weekly pay for an employee
// Anthony Hart
// 02/04/2012

import java.util.Scanner;

public class PayrollProgram {

    public static void main(String [] args) {

        // Create Scanner class input
        Scanner input = new Scanner (System.in);

        // Declare variables for user input
        Srting employeeName;
        double payRate;
        double hoursWorked;

        // Prompt for employee name
        System.out.println ("Please enter Employees' Name");
        employeeName = input.nextLine();

        // Prompt for Hourly rate
        System.out.println ("Please enter Hourly Rate");
        payRate = input.nextDouble();

        // prompt for Hours worked
        System.out.println("Please enter Hours worked");
        hoursWorked = input.nextDouble();

        // Display results
        System.out.printf("\n\nThe Employee %s has earned $%,.2f this week\n\n",employeeName,payRate * hoursWorked);

        // Main loop
        int payRate;

        while (payrate > 0) {
			// ask hourly rate
			// accept input method that is true
			     // Exit loop
			     }

		int houreWorkedp;

		while (hoursWorked >0){
			// ask hourly wage
			// accept input method that is true
				 // Exit loop
			     }

	    }

	    // main end task
	    if (employeeName = true)
	    {
			// ask employee name
			// accept input method that runs true;
		else
	    {
	        // Prompt for exit
        }

    } // end main String
} // end class multiplication



And here are the errors I am dealing with:

Line 55 illegal start of type if (employeeName = true)
line 55 <identifier> expected if (employeeName = true)
line 55 ';' expected if (employeeName = true)
line 56 ';' expected {;
line 65 class, interface, or enum expected

Is This A Good Question/Topic? 0
  • +

Replies To: Compile errors for an employee payroll program.

#2 r.stiltskin   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2032
  • View blog
  • Posts: 5,435
  • Joined: 27-December 05

Re: Compile errors for an employee payroll program.

Posted 04 February 2012 - 09:22 PM

On line 16 you wrote Srting instead of String.

On line 55, you almost certainly meant to write == instead of =. You don't want to do an assignment there.

And then you have an unmatched '{', and no code between the if and the else.
Was This Post Helpful? 1
  • +
  • -

#3 tray2475   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 11-January 12

Re: Compile errors for an employee payroll program.

Posted 04 February 2012 - 09:27 PM

View Postr.stiltskin, on 04 February 2012 - 09:22 PM, said:

On line 16 you wrote Srting instead of String.

On line 55, you almost certainly meant to write == instead of =. You don't want to do an assignment there.

And then you have an unmatched '{', and no code between the if and the else.

Thanks I will fix that and get back to you!
Was This Post Helpful? 0
  • +
  • -

#4 tray2475   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 11-January 12

Re: Compile errors for an employee payroll program.

Posted 04 February 2012 - 09:34 PM

View Postr.stiltskin, on 04 February 2012 - 09:22 PM, said:

On line 16 you wrote Srting instead of String.

On line 55, you almost certainly meant to write == instead of =. You don't want to do an assignment there.

And then you have an unmatched '{', and no code between the if and the else.

Ok I fixed the first to but I am at a loss about which {} I am missing and where it should be, and I am not sure as to what code I am to put between the if and else.
Was This Post Helpful? 0
  • +
  • -

#5 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1824
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Compile errors for an employee payroll program.

Posted 04 February 2012 - 09:37 PM

You closed your main() at line 52, that closing } its match is the opening of main(). So that one should not be there. That makes the if else after it to be outside of any method.
Was This Post Helpful? 1
  • +
  • -

#6 tray2475   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 11-January 12

Re: Compile errors for an employee payroll program.

Posted 04 February 2012 - 10:04 PM

View Postsmohd, on 04 February 2012 - 09:37 PM, said:

You closed your main() at line 52, that closing } its match is the opening of main(). So that one should not be there. That makes the if else after it to be outside of any method.


Thank you that fixed almost every thing but now I get error line 58 'else' without 'if' else

// PayrollProgram.java
// Java application that calculates weekly pay for an employee
// Anthony Hart
// 02/04/2012

import java.util.Scanner;

public class PayrollProgram {

    public static void main(String [] args) {

        // Create Scanner class input
        Scanner input = new Scanner (System.in);

        // Declare variables for user input
        String employeeName;
        double payRate;
        double hoursWorked;

        // Prompt for employee name
        System.out.println ("Please enter Employees' Name");
        employeeName = input.nextLine();

        // Prompt for Hourly rate
        System.out.println ("Please enter Hourly Rate");
        payRate = input.nextDouble();

        // prompt for Hours worked
        System.out.println("Please enter Hours worked");
        hoursWorked = input.nextDouble();

        // Display results
        System.out.printf("\n\nThe Employee %s has earned $%,.2f this week\n\n",employeeName,payRate * hoursWorked);

        // Main loop
        int payRate;

        while (payrate > 0) {
			// ask hourly rate
			// accept input method that is true
			     // Exit loop
			     }

		int houreWorkedp;

		while (hoursWorked >0){
			// ask hourly wage
			// accept input method that is true
				 // Exit loop
			     }


	    // main end task
	    if (employeeName == true){

			// ask employy name
			// accept input method that runs true;
		else
}
	        // Prompt for exit


    } // end main String
}

Was This Post Helpful? 0
  • +
  • -

#7 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1824
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Compile errors for an employee payroll program.

Posted 04 February 2012 - 10:15 PM

That has been answered in above replies, You have to close if block before starting else:
if (employeeName == true){
	            // ask employy name
	            // accept input method that runs true;
}else

Was This Post Helpful? 1
  • +
  • -

#8 tray2475   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 11-January 12

Re: Compile errors for an employee payroll program.

Posted 04 February 2012 - 10:26 PM

View Postsmohd, on 04 February 2012 - 10:15 PM, said:

That has been answered in above replies, You have to close if block before starting else:
if (employeeName == true){
	            // ask employy name
	            // accept input method that runs true;
}else

Duh! That was dumb. That is fixed but now I am getting line 67 reached end of file while parsing }
Was This Post Helpful? 0
  • +
  • -

#9 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1824
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Compile errors for an employee payroll program.

Posted 04 February 2012 - 10:42 PM

Compare your {} pairs to see if anything does not match. Try to figure the errors by yourself, it is a way of learning. Look at your code and see what { has no closing one, or what closing } has no opening one!!!
If you open at else for example else{ then you must close it...
Was This Post Helpful? 1
  • +
  • -

#10 tray2475   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 11-January 12

Re: Compile errors for an employee payroll program.

Posted 04 February 2012 - 10:55 PM

View Postsmohd, on 04 February 2012 - 10:42 PM, said:

Compare your {} pairs to see if anything does not match. Try to figure the errors by yourself, it is a way of learning. Look at your code and see what { has no closing one, or what closing } has no opening one!!!
If you open at else for example else{ then you must close it...

Thanks for your help I just wasnt sure what the error ment. Thanks agian!
Was This Post Helpful? 0
  • +
  • -

#11 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1824
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Compile errors for an employee payroll program.

Posted 04 February 2012 - 11:02 PM

Always try to teach your self how to fix your own errors. This will help a lot in your programming carrier.
Also glad we could help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1