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