Ask Question
11 August, 08:58

Design aPayrollclass that has fields for an employee'sname, ID number, hourly pay rate, and number of hours worked. Write theappropriate accessor and mutator methods and a constructor that accepts theemployee's name and ID number as arguments. The class should also have amethod that returns the employee's gross pay, which is calculated asthenumber of hours worked multiplied by the hourly pay rate. Write anotherclass/programwithmain () methodthat demonstrates the class by creatingaPayrollobject, then asking the user to enter the data for anemployee. The program should display the amount of gross pay earn

+4
Answers (1)
  1. 11 August, 11:09
    0
    public class Payroll {

    private String employeeName;

    private int employeeId;

    private double ratePerHour;

    private double totalWorkHours;

    public Payroll (String employeeName, int employeeId) {

    this. employeeName = employeeName;

    this. employeeId = employeeId;

    }

    public String getemployeeName () {

    return employeeName;

    }

    public voemployeeId setemployeeName (String employeeName) {

    this. employeeName = employeeName;

    }

    public int getemployeeId () {

    return employeeId;

    }

    public voemployeeId setemployeeId (int employeeId) {

    this. employeeId = employeeId;

    }

    public double getratePerHour () {

    return ratePerHour;

    }

    public voemployeeId setratePerHour (double ratePerHour) {

    this. ratePerHour = ratePerHour;

    }

    public double gettotalWorkHours () {

    return totalWorkHours;

    }

    public voemployeeId settotalWorkHours (double totalWorkHours) {

    this. totalWorkHours = totalWorkHours;

    }

    public double getGrossPay () {

    return ratePerHour * totalWorkHours;

    }

    }

    import java. util. Scanner;

    public class PayrollTest {

    public static voemployeeId main (String[] args) {

    Scanner in = new Scanner (System. in);

    String employeeName;

    int employeeId;

    System. out. print ("Enter employee's Name: ");

    employeeName = in. next ();

    System. out. print ("Enter employee's Id: ");

    employeeId = in. nextInt ();

    Payroll payroll = new Payroll (employeeName, employeeId);

    System. out. print ("Enter employee's hourly rate: ");

    payroll. setratePerHour (in. nextDouble ());

    System. out. print ("Enter employee's total hours worked: ");

    payroll. settotalWorkHours (in. nextDouble ());

    System. out. println ("Gross pay = " + payroll. getGrossPay ());

    }

    }

    Explanation:

    Inside the Payroll class, initialize variables for employee name, ID number, hourly pay rate, and number of hours worked. Define the getter and setter methods for the necessary variables inside the Payroll class. Inside the main method, create an object of the Payroll class. Get all the employee information as an input from user. Call the getter function of the class and display the gross pay of employee.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Design aPayrollclass that has fields for an employee'sname, ID number, hourly pay rate, and number of hours worked. Write theappropriate ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers