I need to modify the following 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. For some
reason Icant seem to grasp this simple task. Can some plese help me
out on this? Thanks
import java.util.Scanner;
public class Payroll
{
public static void main(String[] args)
{
// Variable Declaration
double payrate; // Hourly Rate of employee
double hours; // Hours Worked by employee
double grosspay; // Weekly Pay for employee
Scanner keyboard;
Scanner input = new Scanner( System.in );
// Get employee's name
System.out.printf( "Enter the employee's name(Enter stop when
finished):");
String name = input.next();
while(!name.equals("stop"))
{ // Start of name while loop
// Get hourly rate of employee
System.out.printf( "Enter the employee's hourly pay rate: " );
payrate = input.nextDouble();
while (payrate<=0)
{ // start payrate while loop
System.out.printf("\nPayrate must be positive, try again:");
payrate = input.nextDouble();
} // end of payrate while loop
// Get hours worked for the pay period
System.out.printf( "Enter the number of hours worked in this pay
period: ");
hours = input.nextDouble();
while ( hours <= 0 )
{ // start the hours while loop
System.out.printf( "\nSorry you need to enter a positive
number for the Hours:");
hours = input.nextDouble();
} // end hours while loop
// This calculates the gross pay.
grosspay = hours * payrate;
// Display results and reshows what you have entered
System.out.printf( "\nemployee: %s", name );
System.out.printf( "\nhourly rate: $%.2f", payrate );
System.out.printf( "\nhours worked: $%.2f", hours );
System.out.printf( "\nweekly paycheck: $%.2f\n",grosspay);
System.out.printf( "\n\n\nEnter another employee's name (Enter
stop when finished):");
name = input.next();
}// End of name while loop
}
}