Homework 05 Suppose you were given the job to write a Java class to manage emplo
ID: 3887571 • Letter: H
Question
Homework 05
Suppose you were given the job to write a Java class to manage employee payroll information in an HR management system. Each employee will be modeled as a single EmployeePayroll object (much like the Student objects discussed in class). The state of the EmployeePayroll object includes the first name and last name of the employee, a unique 15 digit employee number for each employee, a number of hours that they've worked this week (which could be a fraction of an hour), and the wages per hour the employee earns (measured in dollars and cents). Hours worked and wages per hour are never allowed to fall below zero, and the class should enforce this behavior.
The behavior of the EmployeePayroll object is that any of the above member variables can be accessed (so accessor methods need to be written for them). First name, last name and Employee ID can only be set in a constructor method - there should be no mutators given for these fields, and a special constructor should be written to set these values on initialization. The wages per hour field should have a mutator method (but keep in mind that wages cannot be allowed to be set to less than $0.0). In addition to the above, the class should provide three different ways to change the number of hours worked - on that merely sets the hours as a mutator, one that adds to the hours already in place for the employee, and one that resets the employee's hours to zero. Given the above capabilities of the employee payroll record and the skeleton below, write a Java class that can store an employee payroll record.
Override the methods toString() and equals() inherited from Object for this EmployeePayroll class. The toString() method should return the employee's name, ID, and current calculated pay (wages * hours) as a String. The equals() method should return true if two EmployeePayroll objects have the same employee ids, regardless of name, wages or hours.
Write a short test program that tests the EmployeePayroll class you implemented above. Your short program should create a few new EmployeePayroll objects and test a variety of conditions, including a number that your class should not allow (such as setting a negative hourly wage).
Explanation / Answer
Below is your program. LEt me know if you have any issue: -
public class EmployeePayroll {
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.