Object-oriented programming · 25 / 26 Exercise Medium

Employee hierarchy

Objective

Inheritance lets a subclass reuse a base class and specialize it, and polymorphism makes the same method behave differently depending on the object. With super() the method of the base class is reused.

Instructions

  • Define Employee with name, base and a method salary() that returns the base salary.
  • Define Manager (inherits from Employee, has a bonus and its salary is the base plus the bonus) and Seller (has sales and its salary is the base plus sales // 10). Use super() in the constructor and in salary.
  • Read n and then n lines kind name base extra, with kind equal to employee, manager or seller (for ordinary employees, extra is not used but always appears).
  • Show name: salary for each one, in input order, and at the end Total payroll: t.
Input
3
employee ana 1000 0
manager luis 2000 500
seller eva 800 1234
Output
ana: 1000
luis: 2500
eva: 923
Total payroll: 4423

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise