So I have been looking around and have not been able to find an answer to this. The program is for the most part complete and runs with one exception. When I enter "stop" it still runs through the program before exiting (i.e. after I enter stop it still asks for hourly rate and hours worked before exiting the program). I am just wondering what I could do to fix this so that when I type stop the program immediately exits. Thanks in advance for your response!
Here is my code:
// Week 3 - Day 5 - Payroll Program Part 2
// John Sanders
// IT 215
import java.util.Scanner; // class scanner
public class Payroll2 // set public class
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
String cleanInputBuffer; // input
String empName; // input employee name
double hourlyRate; // input hourly rate
double hoursWorked; //input hours worked
double weeklyPay; // weekly pay amount
boolean end = false; // is the input name stop?
while( end == false ) // as long as end is false, continue
{
System.out.print( "Enter Employee's Name:" ); // prompt to enter employee name
empName = input.nextLine(); // input employee name
if( empName.toLowerCase().equals( "stop" )) // if employee name = stop
end = true; // when stop is detected, change the boolean, which ends the while loop
while( hourlyRate < 0 ) // while the hourly rate is < 0
{
System.out.print( "Enter a positive hourly rate:" ); // print enter a positive hourly rate
hourlyRate = input.nextDouble();
}
while( hoursWorked < 0 ) // while the hours worked are < 0
{
System.out.print( "Enter a positive number of hours worked:" ); // print enter a positive number of hours worked
hoursWorked = input.nextDouble();
}
weeklyPay = hourlyRate * hoursWorked; // multiply hourly rate by hours worked for weekly pay
System.out.printf( "The employee %s was paid $ %.2f this week", empName, weeklyPay ); // print final line
System.out.println();
cleanInputBuffer = input.nextLine();
} // end outer while
} // end main method
} // end class Payroll2