Payroll Program exits at wrong time
Hello everybody!
I am currently taking a Java class at school that requires me to make java programs. I for the most part have my program complete and can run it without errors, but there is one error (or at least I call it that) that I want to fix. When I type "stop" into the employees name prompt it still runs the rest of the program before exiting. I was wondering where I misplaced that part of the code. I want it to actually terminate program upon me pressing "enter" after typing "stop". Thanks in advance for your response!
Here is my code:
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