Loading...
Loading...
An office gives salary raises by employee ID. Apply each raise, then print every employee and the name of the top earner (the first one in the list on a tie).
Write a class Employee with fields id, name and salary and methods void giveRaise(int percent) and String details(). A raise adds salary × percent / 100, rounded down. Find employees with a method that returns null when the ID does not exist.
id percent.RAISED name newSalary or NO EMPLOYEE id. Then n lines id name salary in input order, and finally TOP name.Example
Input
3 101 Asha 50000 102 Ravi 60000 103 Meena 55000 2 101 30 105 10
Output
RAISED Asha 65000 NO EMPLOYEE 105 101 Asha 65000 102 Ravi 60000 103 Meena 55000 TOP Asha
Asha's raise of 15000 makes her the top earner; ID 105 does not exist.
Try the problem first. Open one hint at a time.
static Employee findById(Employee[] staff, int id) loops over the array and returns the matching object, or null after the loop.
Check e == null before calling e.giveRaise(...).
Change the object in the array directly: findById returns a reference to it, not a copy.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor