I have been trying for two days to figure out how to use a loop in my program. It is the ever dreaded payroll program. I can't seem to get the program to start over once the program goes through each question. Can anyone point me in the right direction (other than use a loop...I can't figure out how to get a loop!) I will really appreciate any help!
import java.util.Scanner; // program uses class Scanner
public class PayrollProgram {
/** Creates a new instance of PayrollProgram */
public PayrollProgram() {
}
//main method begins execution of Payroll Program java application
public static void main(String[]args)
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
int number1; // hourly rate
int number2; // hours
int product; // product of number1 and number2
System.out.println("Please enter your name or stop to quit the program:");//prompt
String nameOfEmployee=input.nextLine();
while(nameOfEmployee !="stop"){
}
{
System.out.println("Ending program");
}
System.out.println("Enter hourly rate:$");//prompt
number1 = input.nextInt(); // read first number
while (number1 <=0)//prompt until user enters positive value
{
System.out.println ("Hourly rate must be positive. Please enter hourly rate again");//prompt user to enter in hourly rate again
number1 = input.nextInt(); // read first number
}
System.out.println( "Enter hours: " ); // prompt
number2 = input.nextInt();//read second number
while (number2 <=0)//prompt until user enters positive value
{
System.out.println ("Hours must be positive. Please enter hours worked again");//prompt user to enter in hours worked again
number2 = input.nextInt();//read second number
}
product = number1 * number2; // multiply numbers
System.out.print( nameOfEmployee ); // display employee name
System.out.printf("'s weekly pay is $%d\n",product);
}//end main method
}//end class PayrollProgram