2 回答

TA貢獻1776條經(jīng)驗 獲得超12個贊
像這樣的東西:
public class Manager {
private List<Employee> reports = new ArrayList<Employee>();
public void addReport(Employee e) {
if (e != null) {
this.reports.add(e);
e.setManager(this);
}
}
}
public class Employee {
private Manager manager;
public void setManager(Manager m) {
if (m != null) {
this.manager = m;
}
}
}
以防萬一不清楚,您應該添加您需要的所有其他方法。我只說明了如何在將參考添加到直接報告時更新Manager參考。EmployeeList
您還應該有一個從removeReport中刪除 an并將其設(shè)置為的方法。EmployeeListManagernull
你打算如何Employee在這個中找到一個List?按名字?員工ID?提示:考慮覆蓋equals并hashCode適當?shù)貫槟恼n程。
不Managers也是Employees嗎?老板沒有老板嗎?這是一個層次結(jié)構(gòu),一棵樹。

TA貢獻2019條經(jīng)驗 獲得超9個贊
通常具有不同屬性的對象如下所示:
public class Employee extends EnterpriseMember {
private Manager manager;
private String name; // You probably don't need this because you defined it in the Superclass.
.
.
.
/*Constructor */
public Employee(String name){
super(name);
}
/*Methods */
public Manager getManager(){
return manager;
}
public void setManager(Manager manager){
this.manager = manager
}
// Other getters and setters for the attributes.
}
添加回答
舉報