A company pays every employee a salary. A manager is an employee too, but earns a bonus on top of the salary. Write the two classes so that a manager reuses everything an employee has, and changes only how its pay is worked out.
Implement the class Employee:
Employee(name, salary)creates an employee. The name and the salary are private toEmployee.pay()returns the salary.describe()returns the text<name> earns <pay>, where the amount is whatpay()returns, for exampleAna earns 3000.
and the class Manager, which inherits from Employee:
Manager(name, salary, bonus)lets the parent's constructor store the name and the salary, and stores the bonus itself, private toManager.pay()returns the parent'spay()plus the bonus. Call the parent's version, as in the lesson Calling the Parent Method: the salary is private toEmployee, and the parent'spay()is what knows how an employee is paid.describe()is not written again:Managerinherits it unchanged. Becausedescribe()callspay(), a manager's description shows the manager's pay, bonus included.
The input is a list of people, one per line: employee name salary or manager name salary bonus. For each line, the code that tests your classes creates that object and prints what its describe() returns, on a line of its own. The starter code spells these names the way your language does.
Example 1:
Input:
employee Ana 3000
manager Bob 4000 1000
Output:
Ana earns 3000
Bob earns 5000
Explanation:
Ana's pay is her salary. Bob's pay is the parent's pay, his salary 4000, plus his bonus 1000.
Bob's describe() is Employee's describe(), but the pay() it calls is Manager's.
Example 2:
Input:
manager Cleo 5000 0
employee Dan 5000
Output:
Cleo earns 5000
Dan earns 5000
Explanation: A manager whose bonus is 0 earns exactly the salary, like an employee.
Example 3:
Input:
manager Eve 7000 2500
employee Finn 2800
employee Gus 3100
manager Hana 6000 500
Output:
Eve earns 9500
Finn earns 2800
Gus earns 3100
Hana earns 6500
Explanation: Employees and managers come in any order, and each object keeps its own name and numbers.
Constraints:
0 <= salary <= 1060 <= bonus <= 106- A name is one word of 1 to 20 English letters. Two people may have the same name.
- At most
100people per test case.
Free plan: 30 tutor messages. PRO is unlimited.
