Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a class named WeeklyEmployee. Each instance of WeeklyEmployee must kee

ID: 3550527 • Letter: I

Question

                Implement a class named WeeklyEmployee. Each instance of WeeklyEmployee must keep track of the employee's name, the hourly rate of pay, and the number of hours worked during the current week. Each instance of WeeklyEmployee must be able to compute its own gross pay, which is defined as (hours worked * hourly rate of pay).  A programmer must be able to set the hours worked each week since this changes from week to week. Because BogusBurgers' time clock measures hours worked in tenths of an hour, hours worked must have a fractional part (could make this a double).  

Implement the constructor, a toString method to show the name and dollars per hour, a getName method to return the name, a getGrossPay method that calculates and returns the gross pay, and a setHours method to change the hours worked. The following Java code must generate the output below.

------------------------------------CODE------------------------------------
// This employee worked 30.0 hours at $10.00 per hour
WeeklyEmployee anEmp = new WeeklyEmployee( "Bob Berger", 30.0, 10.00 );

System.out.println(anEmp.toString());

System.out.println(anEmp.getName() + " grossed " + anEmp.getGrossPay());

anEmp.setHours( 40.0 );

System.out.println(anEmp.getName() + " grossed " + anEmp.getGrossPay());

------------------------------------OUTPUT------------------------------------
Bob Berger: $10.00
Bob Berger grossed 300.0
Bob Berger grossed 400.0
_________________________________________________________________________

Hint to complete the class WeeklyEmployee
Step 1: Make the WeeklyEmployee class
Step 2: Declare 3 instance variables for name, rate of pay, and hours worked
Step 3: Declare the constructor with 3 parameters to initialize the instance variables
Step 4: Declare the method toString that returns a String with WeeklyEmployee name, and hourly rate of pay
Step 5: Write the accessor method: getName() that returns the name
Step 6: Write the getGrossPay that computes and returns the pay for each Weekly Employee by multiplying the rate times hours worked
Step 7: Write the mutator method setHours that takes the number of hours worked as a double              (Points : 10)

Explanation / Answer

// WeeklyEmployee.java


public class WeeklyEmployee

{

private String name;

private double hours;

private double hourlyRate;


public WeeklyEmployee(String nm, double hr, double rate)

{

name = nm;

hours = hr;

hourlyRate = rate;

}


public String getName()

{

return name;

}


public double getGrossPay()

{

return hours * hourlyRate;

}


public void setHours(double hr)

{

hours = hr;

  

}

  

public String toString()

{

return name + ": $" + hourlyRate;

}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote