Question: JAVA PROBLEM Consider a Restaurant which wants to calculate the amount to be paid to each of its employees for a particular pay period. A

JAVA PROBLEM

Consider a Restaurant which wants to calculate the amount to be paid to each of its employees for a particular pay period. A casual employee is described by her name (String), hourlyPay (double), the number of service hours in the pay period numOfHours (int) and whether or not she is applicable to a weekend loading rate worksOvertime (boolean).

Since some of them have been working over weekends and public holidays, their overtime pay will also have to be computed. For this, We'll make a WeekendPayCalculator class.

Two reasons as to why this is a good candidate for a static nested class are:

It has limited use in any other context. Restaurants use it frequently whilst issuing staff paychecks.

In short, we require WeekendPayCalculator only when we are using the employee's data, therefore it makes sense to logically group them together.

create a class Staff that stores information about an employee including: name, hourlyPay, numOfHours and worksOvertime.

The class should have a constructor Staff(String name, double hourlyPay, int numOfHours, boolean worksOvertime). The class should have a public instance method, getName() that returns a String reflecting the employee's name. The class should have a public instance method, double getTotalPay(double extraPay) that takes in the extra Pay earned by the employee and returns her total pay for the period based on whether they have been working overtime or not

Also create a public nested class WeekendPayCalculator which stores information about the weekend loadingRate (double) The class should have a public instance method, void setLoadingRate(double rate) that enables us to assign a value to loadingRate.

The class should have a public instance method, double calcOvertime(double hourlyPay) that takes in the basic hourlyPay of an employee and returns the extra pay that she is entitled to based on the loadingRate. The overtime pay is calculated as loadingRate * hourlyPay

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!