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

Suppose you were given the job to write a Java class to manage employee payroll

ID: 3562743 • Letter: S

Question

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 EmployeePayrollobject (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 gas pump and the skeleton below, write a Java class that can control the gas pump.

Explanation / Answer

Each employee will be modeled as a single EmployeePayrollobject (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.

Thus, it is possible to configure a category and then retrieve the same instance somewhere else in the code without passing around references. Categories can be created and configured in any order. In particular, a parent category will find and link to its children even if it is instantiated after them. The log4j environment typically configures at application initialization, preferably by reading a configuration file, an approach we'll discuss shortly.

Log4j makes it easy to name categories by software component. That can be accomplished by statically instantiating a category in each class, with the category name equal to the fully qualified name of the class -- a useful and straightforward method of defining categories. As the log output bears the name of the generating category, such a naming strategy facilitiates identifying a log message's origin. However, that is only one possible, albeit common, strategy for naming categories.

or we'll end up leaving the thread hanging in permanent suspense. But we have no way of knowing if the applet will ever be restarted, so just putting a call to resume() in the applet's start() method won't work. Leaving the suspended thread around forever might not hurt us, but it's not good programming practice to be wasteful. What we need is a way to guarantee we can clean up our mess if the applet is never used again. What to do?

There is a solution for this dilemma, but in many cases, like with our simple Clock, it's just easier to use stop(), with a subsequent call to start() if necessary. In cases where it is expensive to set up and tear down a thread, we could make the following modifications to UpdateApplet:

These modifications change UpdateApplet so that it suspends and restarts its updateThread, rather than killing and recreating it. The new start() method creates the thread and calls start() if updateThread is null; otherwise it assumes that the thread has been suspended, so it calls resume(). The applet's stop() method simply suspends the thread by calling suspend().

What's new here is the destroy() method. This is another method that UpdateApplet inherits from the Applet class. The method is called by the Java environment when the applet is going to be removed (often from a cache). It provides a place where we can free up any resources the applet is holding. This is the perfect place to cut the suspense and clean up after our thread. In our destroy() method, we check to see that the thread exists, and if it does, we call stop() to kill it and set its reference to null.

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