Question: Modify EmployeeData's compareTo() method so that elements are sorted based on the employees' department number (deptNum) and ID (emplID). Specifically, employee's should first be sorted
Modify EmployeeData's compareTo() method so that elements are sorted based on the employees' department number (deptNum) and ID (emplID). Specifically, employee's should first be sorted in ascending order according to department number first, and those employees within the same department should be sorted in ascending order according to the employee ID.
| EmployeeData.java EmployeeRecords.java public class EmployeeData implements Comparable @Override public int compareTo(EmployeeData otherEmpl) { String fullName = ""; // Full name, this employee String otherFullName = ""; // Full name, comparison employee int comparisonVal = 0; // Outcome of comparison // Compare based on department number first comparisonVal = deptNum.compareTo(otherEmpl.deptNum); // If in same organization, use name if (comparisonVal == 0) { fullName = lastName + firstName; otherFullName = otherEmpl.lastName + otherEmpl.firstName; comparisonVal = fullName.compareTo(otherFullName); } return comparisonVal; } @Override public String toString() { return lastName + " " + firstName + " \tID: " + emplID + "\t\tDept. #: " + deptNum; } }
|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
