Hello,
I need help badly. I was able to compile the program but when i ran it, it didn't do what it is supposed to do.
The program should continue to promt for next employee's info until user enters "stop".
I am not sure what I am missing.. Any help would be very much appreciated.
------
import java.util.Scanner;
public class PayrollProgramPart2
{
public static void main( String args[] )
{
System.out.println( "Welcome to the Payroll Program!" );
boolean stop = false; // Loop until user types "stop" as the employee name.
{
Scanner input = new Scanner(System.in );
System.out.print( "Enter Employee's Name or stop to exit program: " );
String empName = input.nextLine(); // employee name
if ( empName.equals("stop"))
{
System.out.println( "Program Exited" );
stop = true;
}
else
{
double hourlyRate; // hourly rate
double hoursWorked; // hours worked
double weeklyPay; // Weekly Pay for employee
System.out.print( "Enter hourly rate: " ); // prompt for hourly rate
hourlyRate = input.nextDouble();
while (hourlyRate <= 0) // prompt until positive value is entered
{
System.out.print( "Hourly rate must be a positive number. " +
"Please enter the hourly rate again: " );
hourlyRate = input.nextDouble(); // read hourly rate again
}
System.out.print( "Enter hours worked: " ); // prompt for hours worked
hoursWorked = input.nextDouble();
while (hoursWorked <= 0) // prompt until a positive value is entered
{
System.out.print( "Hours worked must be a positive number. " +
"Please re-enter hours worked: " ); // prompt for positive value for hours worked
hoursWorked = input.nextDouble(); // read hours worked again
}
weeklyPay = (double) hourlyRate * hoursWorked; // multiply sum
System.out.printf( "%s%.2f\n",
"Employee: " + empName + " Weekly Pay:", weeklyPay ); // display employee's weekly gross income in U.S. dollar
}
}
} // end method main
} // end class PayrollPart2