I'm trying to create a program that continuously asks for user input until the user inputs "stop" for employee name which will terminate the program. I have compiled the following code but when the program runs through the second time it skips the user input for the employee name and goes directly to number of hours worked. What am I doing wrong?
// Weekly pay calculator
// This program will calculate weekly pay amount for an employee when given hours worked and rate of pay
import java.util.Scanner;
public class Pay2
{
//main method
public static void main( String args[])
{
//create Scanner for obtaining inputs from user
Scanner input = new Scanner( System.in );
double hours; //hours worked
double rate; // rate of pay
String employeeName; //name of worker
double pay; // product of hours and rate
String stop;
boolean empName = false;
while ( !empName )
{
System.out.printf( "Enter employee name: " ); //prompt
employeeName = input.nextLine(); //read employee name from user
System.out.println();
if(employeeName.equals("stop"))
{empName = true;
}
else
{empName = false;
}
System.out.printf( "Enter hours worked by %s : ", employeeName ); //prompt
hours = input.nextDouble(); //read hours worked
System.out.println();
System.out.printf( "Enter rate of pay for %s :$", employeeName ); //prompt
rate = input.nextDouble();//read rate of pay
System.out.println();
pay = hours * rate; //multiply hours times rate to get weekly pay
System.out.printf( "Employee name: %s \nWeekly pay amount: $%.2f", employeeName, pay); //display name and pay amount
System.out.println();
} //end while
} //end main
} //end class