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

design a payroll class that has fields for an employee\'s name, ID number, hourl

ID: 3546408 • Letter: D

Question

design a payroll class that has fields for an employee's name, ID number, hourly pay rate and the number of hours worked. Write the appropriate accessor and mutator methods and a constructor that accepts the employee's name and ID number as arguments. The class should also have a method that returns the employee's gross pay, which is calculated as the number of hours worked multiplied by the hourly pay rate. Write a program that demonstrates the class by creating a Payroll object, then asking the user to enter the data for an employee. The pogram should display the amount of gross pay earned

Explanation / Answer

import java.util.Scanner; //Needed for scanner class.

02

03

public class Payroll

04

{

05

private String EmployeeName;

06

private int IDnumber;

07

private double HourlyPayRate;

08

private double HoursWorked;

09

private double GrossPay;

10

11

/**

12

Constructor

13

@param Name The name to store in EmployeeName.

14

@param ID The ID to store in Employee ID number.

15

*/

16

public Payroll(String Name, int ID)

17

{

18

EmployeeName = Name;

19

IDnumber = ID;

20

}

21

public String getEmployeeName()

22

{

23

return EmployeeName;

24

}

25

public int getIDnumber()

26

{

27

return IDnumber;

28

}

29

public void setHourlyPayRate(double HourlyRate)

30

{

31

HourlyPayRate = HourlyRate;

32

}

33

public double getHourlyPayRate()

34

{

35

return HourlyPayRate;

36

}

37

public void setHoursWorked(double hoursWorked)

38

{

39

HoursWorked = hoursWorked;

40

}

41

public double getHoursWorked()

42

{

43

return HoursWorked;

44

}

45

public double getGrossPay()

46

{

47

return HourlyPayRate * HoursWorked;

48

}

49

}