Write a class Staff (name, department, salary, getters, toString → Lina(IT,9000)) and StaffSort, which reads name department salary lines and prints the list sorted in five ways:
- by name, with a hand-written lambda
(a, b) -> …; - by salary, with
Comparator.comparingInt; - "payroll order": department, then salary descending, then name (
comparing(…).thenComparing(…reversed()).thenComparing(…)); - the payroll comparator
.reversed(); - by name length, ties by name;
and finally the highest-paid person (Collections.max; on a tie the alphabetically first name).
For the input
Lina IT 9000
Omar HR 7000
Mei IT 9000
Ana HR 8000
Bo IT 6500
the program prints
by name: Ana(HR,8000) Bo(IT,6500) Lina(IT,9000) Mei(IT,9000) Omar(HR,7000)
by salary: Bo(IT,6500) Omar(HR,7000) Ana(HR,8000) Lina(IT,9000) Mei(IT,9000)
payroll order: Ana(HR,8000) Omar(HR,7000) Lina(IT,9000) Mei(IT,9000) Bo(IT,6500)
reversed: Bo(IT,6500) Mei(IT,9000) Lina(IT,9000) Omar(HR,7000) Ana(HR,8000)
by name length: Bo(IT,6500) Ana(HR,8000) Mei(IT,9000) Lina(IT,9000) Omar(HR,7000)
highest salary: Lina(IT,9000)