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 { private String firstName; // First Name private String lastName; // Last Name private Integer emplID; // Employee ID private Integer deptNum; // Department Number EmployeeData(String firstName, String lastName, Integer emplID, Integer deptNum) { this.firstName = firstName; this.lastName = lastName; this.emplID = emplID; this.deptNum = deptNum; }

@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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!