Question 1
An organization maintains employee records with two attributes: currentExp (experience in the current company) and totalExp (overall work experience). Write a Java program that accepts currentExp and totalExp for 4 Employee objects, stores them in a TreeSet, and prints them in sorted order.
Employees are sorted by currentExp in ascending order. If the currentExp values are the same, they are sorted by totalExp in ascending order.
Requirements:
- Define the
compareTomethod comparingcurrentExpfirst, thentotalExp. - Return a negative number if this employee comes before the other, a positive number if it comes after, and 0 if they are equal.
- A
TreeSetautomatically removes duplicates.
Input: 4 lines, each with two integers: the employee's experience in the current company and the total work experience. For each employee, totalExp >= currentExp.
Output: all Employee records stored in the TreeSet, in sorted order, one per line, in the format CurrentExp:<currentExp> TotalExp:<totalExp>.