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.Scann er;
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.prin tf( "Enter the employee's name(Enter stop when
finished):");
String name = input.next();
while(!name.equ als("stop"))
{ // Start of name while loop
// Get hourly rate of employee
System.out.prin tf( "Enter the employee's hourly pay rate: " );
payrate = input.nextDoubl e();
while (payrate<=0)
{ // start payrate while loop
System.out.prin tf("\nPayrate must be positive, try again:");
payrate = input.nextDoubl e();
} // end of payrate while loop
// Get hours worked for the pay period
System.out.prin tf( "Enter the number of hours worked in this pay
period: ");
hours = input.nextDoubl e();
while ( hours <= 0 )
{ // start the hours while loop
System.out.prin tf( "\nSorry you need to enter a positive
number for the Hours:");
hours = input.nextDoubl e();
} // end hours while loop
// This calculates the gross pay.
grosspay = hours * payrate;
// Display results and reshows what you have entered
System.out.prin tf( "\nemployee : %s", name );
System.out.prin tf( "\nhourly rate: $%.2f", payrate );
System.out.prin tf( "\nhours worked: $%.2f", hours );
System.out.prin tf( "\nweekly paycheck: $%.2f\n",grossp ay);
System.out.prin tf( "\n\n\nEnte r another employee's name (Enter
stop when finished):");
name = input.next();
}// End of name while loop
}
}
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.Scann er;
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.prin tf( "Enter the employee's name(Enter stop when
finished):");
String name = input.next();
while(!name.equ als("stop"))
{ // Start of name while loop
// Get hourly rate of employee
System.out.prin tf( "Enter the employee's hourly pay rate: " );
payrate = input.nextDoubl e();
while (payrate<=0)
{ // start payrate while loop
System.out.prin tf("\nPayrate must be positive, try again:");
payrate = input.nextDoubl e();
} // end of payrate while loop
// Get hours worked for the pay period
System.out.prin tf( "Enter the number of hours worked in this pay
period: ");
hours = input.nextDoubl e();
while ( hours <= 0 )
{ // start the hours while loop
System.out.prin tf( "\nSorry you need to enter a positive
number for the Hours:");
hours = input.nextDoubl e();
} // end hours while loop
// This calculates the gross pay.
grosspay = hours * payrate;
// Display results and reshows what you have entered
System.out.prin tf( "\nemployee : %s", name );
System.out.prin tf( "\nhourly rate: $%.2f", payrate );
System.out.prin tf( "\nhours worked: $%.2f", hours );
System.out.prin tf( "\nweekly paycheck: $%.2f\n",grossp ay);
System.out.prin tf( "\n\n\nEnte r another employee's name (Enter
stop when finished):");
name = input.next();
}// End of name while loop
}
}
Comment