Loading...
Loading...
An office pays each employee a salary and a bonus, and the bonus may never be more than 20% of the salary (rounded down). If the salary is lowered, a bonus above the new cap is cut down to the cap.
Write a class Employee with private name, salary and bonus (it starts at 0), boolean setSalary(long s) (salary must be positive), boolean setBonus(long b), getBonus(), getBonusCap() and details().
salary x, bonus x or show.salary: SALARY x, SALARY x, BONUS CUT TO b or INVALID SALARY x. bonus: BONUS x, INVALID BONUS x (negative) or BONUS ABOVE CAP c. show: name SALARY s BONUS b TOTAL t.Example
Input
Asha 50000 5 bonus 12000 bonus 10000 salary 40000 show salary 0
Output
BONUS ABOVE CAP 10000 BONUS 10000 SALARY 40000, BONUS CUT TO 8000 Asha SALARY 40000 BONUS 8000 TOTAL 48000 INVALID SALARY 0
The cap is 10000; lowering the salary to 40000 cuts the bonus to 8000.
Try the problem first. Open one hint at a time.
The cap is a getter worked out from the salary: salary * 20 / 100.
setSalary must check the bonus again after the salary changes.
In main, remember the bonus before calling setSalary to tell whether it was cut.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor