Question: IN PHP In this question, you will write four classes namely, Bonus, BirthdayBonus, LongServiceBonus and PerformanceBonus, where Bonus is the superclass of the other three

IN PHP

In this question, you will write four classes namely, Bonus, BirthdayBonus, LongServiceBonus and PerformanceBonus, where Bonus is the superclass of the other three classes. These three subclasses represent different types of bonuses for employees in an organisation. The class Bonus, an abstract class, contains two data members to store the salary and the type of the bonus. There are three types of bonuses: birthday bonus, long service bonus and performance bonus. It has a constructor, a get function (getType()) to return the type of bonus and the calculate() function that is abstract. BirthdayBonus, a subclass of Bonus, has a data member to store the number of months (1 to 12). Its constructor takes two arguments: one for salary and one for months. The constructor also initializes its type correctly in the data member type of its superclass Bonus. The function calculate() calculates bonus on a prorata basis on the number of months an employee worked in the company. If the number of months stored in months is 12, then it simply returns the salary. Otherwise, it will be a percentage of the salary and this percentage is determined by the percentage of months the employee worked for the company. For example, if the number of months is 3, then calculate() will return 25% (3/12 * 100) of the salary. LongServiceBonus, another subclass of Bonus calculates long service bonus based on the start date of employment stored in its data member. Its constructor takes two arguments: one for the salary and one for the start date of employment. The constructor also initializes its type correctly in the data member type of its superclass Bonus. Long service bonus is only awarded when the number of years of service is a multiple of 5 (for example 5, 10, 15, 20, 25, etc.). When the duration of employment is a multiple of 5, the bonus is calculated by adding a percentage of the salary to the salary and this percentage is based on the duration of employment. For example, if the duration of employment is 5 years, then the long service bonus is calculated by adding 5% of the salary to the salary. When doing the calculation, make sure that the duration is based on whether the employee has completed 5 (or multiples of 5) years. When calculating the duration, take into account the days, months and years of the start and current dates. PerformanceBonus, another subclass of Bonus calculates a performance bonus based on the performance score stored its data member. Its constructor takes two arguments: one for the salary and one for the performance score (between 1 and 5). A performance bonus is only awarded when the performance score is equal to or greater than 3.1. Similar to long service bonus, a performance bonus is calculated by adding a percentage of the salary to the salary and this percentage is based on the performance score. For example, if the performance score is 3.1, then the performance service bonus is calculated by adding 3.1% of the salary to the salary. Create an array that contains three objects each of BirthdayBonus, LongServiceBonus and PerformanceBonus. Iterate through the array and invoke (and display) the values returned by getType() and calculate().

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 Accounting Questions!