Here is what I have so far:
package payrollpart2;
/**
*
* @author Darryl
*/
import java.util.Scanner;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//declare program variables
String employeeName;
double hourlyRate;
double hoursWorked;
double sum;
boolean isValid = true; //by default a boolean is always false
while(isValid)
{
//prompt and accept the student name
System.out.println("Please enter employee's name or enter stop to exit:");
employeeName = input.next();
if(!employeeName.equalsIgnoreCase("Stop"))
{
//prompt and accept for the first grade
System.out.println("Please enter employee's hourly rate: $");
hourlyRate = input.nextDouble();
// if(grade1 < 0) //error checking
while(hourlyRate<0)
{
System.out.println("Employee's hourly rate must be a positive number. Please re-ener:");
hourlyRate = input.nextDouble();
}
//prompt and accept for the first grade
System.out.println("Please enter employee's hours worked: ");
hoursWorked = input.nextDouble();
if(hoursWorked < 0) //error checking
{
System.out.println("Employee's hours worked must be a positive number. Please re-ener:");
hoursWorked = input.nextDouble();
}
sum = hourlyRate * hoursWorked;
System.out.printf("Employee Name: %s\n", employeeName); //display employee name
System.out.printf( "Hourly Rate: $%.2f\n", hourlyRate ); //display hourly pay rate
System.out.printf( "Hours Worked: %.2f\n", hoursWorked ); //display hours worked for the week
System.out.printf( "Weekly Pay: $%.2f\n", sum ); // display sum;
}
else
{
isValid = false;
System.out.println("Thank you and Goodbye");
} //end of else
} //end of while(isValid)
}
}
This program compiles successfully on netbeans, but you can only enter the first name. I want it to be able to enter the full name.
In line 30 I changed the: employeeName = input.next();
to: employeeName = input.nextLine();
Although this does allow me to enter the full name, it ends up skipping the prompt for employee name the next time through the loop. I can't seem to figure out how to get it to work. I appreciate any help that anyone can provide.