Hello everybody,
I know what I want to do with the code, but I am not sure where exaclty to put the "if" statements.
I am working on a weekly payroll program and I need to put in an if statement so it throws an error if the weekly hours or pay is a negative number.
Below is what i have for the code and where I thought the "if" statements needed to go, but it won't work right with them there.
Thanks in advance.
COY
package payroll_program;
// Payroll.java
import java.util.Scanner; // required for keyboard input
public class payroll
{
// main method
public static void main(String args[] )
{
// Create a Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
String employeeName;
String cleanInputBuffer;
double hourlyWageInDollars = 0.0;
double hoursWorkedInWeek = 0.0;
double weeklyWageInDollars = 0.0;
while ( true )
{
System.out.printf( "*********************************" );
System.out.printf( "Payroll Program" );
System.out.printf( "********************************\n\n" );
//Input the name of the employee
System.out.printf( "Please enter the employee's name ('stop' to quit): " );
employeeName = input.nextLine();
if ( employeeName.equalsIgnoreCase( "stop" ) )
if ( hoursWorkedInWeek <= 0.0 )
System.out.println( "stop" );
if ( hourlyWageInDollars <= 0.0 )
System.out.println("stop" );
{
break;
}
// prompt and input hours worked
System.out.println("Please enter hours worked: " );
Double hoursWorked = input.nextDouble();
System.out.println();
// prompt and input pay rate
System.out.println( "Please enter pay rate: " );
Double payRate = input.nextDouble();
System.out.println();
double weeklyPay = hoursWorked * payRate;
System.out.printf( "Weekly pay is $%.2f", weeklyPay );
} // end method main
} // end class Payroll
} // End while