I have constructed a source code for Java Payroll Part 3: I'm receiving the following error when I try to compile my program: PayrollPart3.java:56: 'else' without 'if' ^else
Any advice would be appreciated to why I am getting this error. Thanks!

// Fig. 1.3: Payroll Part 3
// Program stores and retrieves employee's data.

import java.util.Scanner;// program to use import scanner

public class PayrollPart3
{

    // main method begins java execution
    public static void main (String[] args)

   {
	   System.out.println( "Welcome to the Payroll Program!");
        Employee emp = new Employee();
        Scanner input = new Scanner(System.in);// create scanner to obtain input from command window

        double payRate;
        double hoursWorked;
        double earnedPay;

        while (true)
        {
			//Get employee name
            System.out.println("\nEnter Employee's Name or stop to exit program :");
            emp.setName(input.next());

			if(!emp.getName().equalsIgnoreCase("Stop"));// program exits if "stop" is entered

            {
                    //Get pay rate
                    System.out.print ("Enter Employee payRate: $"); //prompt for pay rate
                    emp.setpayRate(input.nextDouble());

                    while (emp.getpayRate() <= 0)
                    {

                        System.out.println ("Invalid amount, pay rate must be positive number");
                        System.out.print ("Please re-enter valid pay rate: $");
                        emp.setpayRate(input.nextDouble());
                        // Loop until valid number is entered for pay rate: while (setpayRate < 0.0)
                    } // end while

                    // Get hours worked
                    System.out.print ("Enter number of hours worked: ");//prompt for hours worked
                    emp.sethoursWorked(input.nextDouble());
                    while (emp.gethoursWorked() <= 0 )
                    {

                        System.out.println ("Invalid amount, hours worked must be a positive number");
                        System.out.print ("Please  re-enter valid hours worked: ");
                        emp.sethoursWorked(input.nextDouble());
                    }
				//Display output results and call methods in class
                System.out.printf("%s's weekly earned pay is: $%.2f\n", emp.getName(), emp.getpayRate()*emp.gethoursWorked ());
            }
            else
                break;
        } // end while (true)

    } // end main

}//end class PayrollPart3


//  Class Employee
class Employee
{
	//fields
    private String name;
    private double hourlyRate;
    private double hoursWorked;

    public Employee ()
    {
        name = "";
        hourlyRate = 0.0;
        hoursWorked = 0.0;
    }

    //  constructor
    public Employee(String employeenameIn, double hourlyRateInDollarsIn, double hoursWorkedInWeekIn) {
        name = employeenameIn;
        hourlyRate = hourlyRateInDollarsIn;
        hoursWorked = hoursWorkedInWeekIn;
    } // end constructor

    public void setName (String name) {
        this.name = name;
    }

    public String getName () {
        return name;
    }

    public void setpayRate (double payRate) {
        this.hourlyRate = payRate;
    }

    public double getpayRate () {
        return hourlyRate;
    }

    public void sethoursWorked (double hours) {
        this.hoursWorked = hours;
    }
    //call "getters" - retrieve information
    public double gethoursWorked () {
        return hoursWorked;
    }

    public double getearnedPay () {
        return hourlyRate * hoursWorked;
    }

} // end class Employee

if(!emp.getName().equalsIgnoreCase("Stop"));// try removing the semicolon at the end of your if statement

Thanks that did the trick I had a feeling I was overlooking something simple. But I have one more question , How would I incorporate a message to the user that after they've enter "stop" that the program is exiting? I've tried different message statements and I end up with the same "if else" error.

I'm assuming you mean something like this--

//...
            else{
                System.out.println("Program exiting. Thank you, and have a nice day!");
                break;
            }
        } // end while (true)
//...

Tnakf you I see what my problems was I was fixed on stating my message under the if statement instead of the else statement. Thank you so much for your help!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.