Modify the Payroll Program so that it uses a class to store and retrieve the employee's
name, the hourly rate, and the number of hours worked. Use a constructor to initialize the
employee information, and a method within that class to calculate the weekly pay. Once
stop is entered as the employee name, the application should terminate.
Here is my code so far. I need help creating the class that does what the question asks. Can anyone help me?
import java.util.Scanner; // program uses class Scanner
// Payroll program that calculates an employee's weekly pay.
public class PayApp
{
// main method begins execution of Java application
public static void main(String args[])
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
double hourlyRate = 0.0; //employee's payrate
double hoursWorked = 0.0; //employee's total hours
double pay; // total of hourlyRate and hoursWorked
String name = ""; //sets variable name
System.out.print( "Enter employee's name - Enter stop to end: " ); //prompt
System.out.flush(); //Flushes the buffer.
name = input.nextLine(); //read employee's name
while ( !name.equals( "stop" ) ) //ends program after entering stop for the employee name
{
System.out.print( "Enter hourly rate: " ); //prompt
hourlyRate = input.nextDouble(); //reads first number
System.out.flush(); //Flushes buffer.
while ( hourlyRate < 0.0 ) //starts while loop to make sure a positive number is entered.
{
System.out.print( "Input must be a positive number. Please Re-enter hourly rate: " ); //prompt
hourlyRate = input.nextDouble(); //reads first number
input.nextLine(); //prompt user for input
}
System.out.print( "Please Enter Hours Worked: " ); //prompt
hoursWorked = input.nextDouble(); //reads second number
input.nextLine(); //prompt user for input
while ( hoursWorked < 0.0 ) //Checks that a positive (valid) number is entered.
{//starts while loop
System.out.print( "Input must be a positive number. Please Re-enter Hours Worked: " ); //prompt
hoursWorked = input.nextDouble(); //read second number from user
input.nextLine(); //prompt user for input
}
pay = hourlyRate * hoursWorked; //calculates pay
System.out.printf( "Employee: %s\n", name ); //display employee's name
System.out.printf( "Total Pay for this period is $%.2f\n", pay ); //display total pay for the period
} //ends while loop
} //end method main
}//end class PayApp