Loading...
Loading...
Every employee gets a basic salary plus a 10% allowance (rounded down). A manager also gets a fixed bonus on top. An intern gets only a stipend, with no allowance.
Write Employee (private name and basic, long pay()), Manager extends Employee (adds bonus; pay() uses super.pay()) and Intern extends Employee whose pay() returns the stipend alone. Print each pay, the payroll total and the top earner (the first one on a tie).
E name basic, M name basic bonus or I name stipend.name pay, then TOTAL sum and TOP name.Example
Input
3 E Asha 30000 M Ravi 50000 8000 I Meena 12000
Output
Asha 33000 Ravi 63000 Meena 12000 TOTAL 108000 TOP Ravi
Asha 30000 + 3000; Ravi 50000 + 5000 + 8000; Meena only 12000.
Try the problem first. Open one hint at a time.
Manager.pay() is super.pay() + bonus: the allowance rule is not written twice.
Intern(String name, long stipend) can call super(name, stipend) and its pay() returns getBasic().
Keep topName and topPay in main and change them only on a strictly higher pay.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor