Can't make if..else work for me!
I am trying to have the program check for positive numbers and I can't get it to check it for me. Here is the coding:
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();
if(nameOfEmployee.equals("stop"))//Check whether user has entered stop
{
System.out.println("Ending program");
}
else
System.out.println("Enter hourly rate:$");//prompt
number1 = input.nextInt(); // read first number
if (number1 <=0)//prompt until user enters positive value
{
System.out.print ("Hourly rate must be positive. Please enter hourly rate again");//prompt user to enter in hourly rate again
}
else
System.out.println( "Enter hours: " ); // prompt
number2 = input.nextInt();//read second number
if (number2 <=0)//prompt until user enters positive value
{
System.out.print ("Hours must be positive. Please enter hours worked again");//prompt user to enter in hours worked again
}
product = number1 * number2; // multiply numbers
System.out.print( nameOfEmployee ); // display employee name
System.out.printf("'s weekly pay is $%d\n",product);
} //end method main
} //end class PayrollProgram
Here is the outcome:
Please enter your name or stop to quit the program:
af
Enter hourly rate:$
-5
-5
Hourly rate must be positive. Please enter hourly rate againHours must be positive. Please enter hours worked againaf's weekly pay is $25
BUILD SUCCESSFUL (total time: 7 seconds)
I have to hit enter twice to get the last message. How do I get it to work at the end?
Thank the stars for you all!

