I am now on part 3 of a payroll program for my Java class but I did not add the while loop in last week so I need to figureout what I did wrong so I can do part 3.
The program should loop until the user enters "stop" It sort of does it but after the program is complete it asks for pay rate again, not employee name. I see why but I cannot figure out how to fix it. I found this forum and I am hoping someone can help me.
This is what I have:
package payroll4;
/**
*
* @author Brianna
*/
import java.util.Scanner;
public class Payroll4 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
{
Scanner input = new Scanner( System.in);
System.out.println();
System.out.print( "Enter Employee's Name or Stop if you would like to exit: ");
String empName = input.nextLine();
while(!(empName.equals("stop")))
{
double hourlyRate; //rate per hour
double hoursWorked; //hours worked
double weeklyPay; //hours*rate
System.out.print( "Enter the rate per hour: "); //prompt for hourly rate
hourlyRate = input.nextDouble(); //read hourly rate
while (hourlyRate <= 0) //prompt until the number is positive
{
System.out.print( "Rate per hour must be a positive number." +
"Please re-enter the rate per hour: " );
hourlyRate = input.nextDouble(); //read rate per hour again
}
System.out.print( "Enter hours worked:" ); //prompt for number of hours
hoursWorked = input.nextDouble(); //read hours worked
while (hoursWorked <= 0) //prompt until the number is positive
{
System.out.print( "Number of hours worked must be a positive " +
"number. Please re-enter the number of hours worked: " ); //prompt for number of hours worked
hoursWorked = input.nextDouble(); //read hours worked again
empName =input.next();
}//end while
{
//calculation of weekly pay.
weeklyPay =(float) hourlyRate*hoursWorked; // *Sum
}
{
//Display of out
System.out.print( empName ); //display the employee name
System.out.printf( "'s pay this week is: $%,.2f\n",weeklyPay);
}
}
}
} //end method main
}// end class Payroll4