Both files are posted, Update the Employee class to facilitate sorting of an ArrayList list, grouping and orde

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Both files are posted, Update the Employee class to facilitate sorting of an ArrayList list, grouping and orde

Post by answerhappygod »

Both files are posted,
Update the Employee class to facilitate sorting of
an ArrayList<Employee> list, grouping and ordering
the list using these criteria:
public class Person {
private String familyName;
private String givenName;
private int id;
public Person(String familyName, String
givenName, int id) {

setFamilyName(familyName);

setGivenName(givenName);
setId(id);
}
public Person() {
setFamilyName("");
setGivenName("");
setId(0);
}
public void setFamilyName(String familyName)
{
this.familyName =
familyName;
}
public void setGivenName(String givenName)
{
this.givenName =
givenName;
}
public void setId(int id) {
this.id = id;
}
public String getFamilyName() {
return familyName;
}
public String getGivenName() {
return givenName;
}
public int getId() {
return id;
}

@Override
public String toString() {
String fmt =
"Person[familyName=%s,givenName=%s,id=%d]";
String str =
String.format(fmt, familyName, givenName, id);
return str;
}
}
public class Employee extends Person {
private String title;
private String contractOrg;
public Employee(String familyName, String
givenName, int id, String title, String contractOrg) {
super(familyName, givenName, id);
setTitle(title);

setContractOrg(contractOrg);
}
public Employee() {
setTitle("");
setContractOrg("");
}
public void setTitle(String title) {
this.title = title;
}
public void setContractOrg(String
contractOrg) {
this.contractOrg =
contractOrg;
}
public String getTitle() {
return title;
}
public String getContractOrg() {
return contractOrg;
}
public String getEmployeeInfo() {
return title + " (" +
contractOrg + ")";
}
@Override
public String toString() {
String fmt =
"Employee[title=%s,contractOrg=%s]%s";
String str =
String.format(fmt, title, contractOrg, super.toString());
return str;
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply