class Dept{
private int deptno;
private String dname;
private String loc;
private Emp emps[];
public Dept(){
}
public Dept(int deptno,String dname,String loc){
this.deptno = deptno;
this.dname = dname;
this.loc = loc;
}
public void setDeptno(int d){
this.deptno = d;
}
public void setDname(String n){
this.dname = n;
}
public void setLoc(String l){
this.loc = l;
}
public void setEmp(Emp[] e){
this.emps = e ;
}
public int getDeptno(){
return deptno;
}
public String getDname(){
return dname;
}
public String getLoc(){
return loc;
}
public Emp[] getEmp(){
return emps;
}
public String getInfo(){
return "部门编号:" + this.deptno + ",名称:" + this.dname + ",位置:" + this.loc;
}
}
class Emp{
private int empno;
private String ename ;
private String job ;
private double sal;
private double comm ;
private Dept dept;
private Emp mgr;
public Emp(){
}
public Emp(int empno,String ename, String job, double sal, double comm){
this.empno = empno;
this.ename = ename ;
this.job = job;
this.sal = sal ;
this.comm = comm ;
}
public void setEmpno(int e){
this.empno = e;
}
public void setEname(String n){
this.ename = n ;
}
public void setJob(String j){
this.job = j ;
}
public void setSal(double s){
this.sal = s ;
}
public void setComm(double c){
this.comm = c ;
}
public void setMgr(Emp m){
this.mgr = m;
}
public void setDept(Dept d){
this.dept = d;
}
public int getEmpno(){
return empno;
}
public String getEname(){
return ename;
}
public String getJbo(){
return job;
}
public double getSal(){
return sal;
}
public double getComm(){
return comm;
}
public Emp getMgr(){
return mgr;
}
public Dept getDept(){
return dept;
}
public String getInfo(){
return "雇员编号:" + this.empno + ",姓名:" + this.ename + ",职位:" + this.job + ",工资:" + this.sal + ",佣金:" + this.comm ;
}
}
public class TestDemo {
public static void main(String[] args) {
Dept dept = new Dept(10,"ACCOUNTING","New York");
Emp ea = new Emp(1234,"Yiyao","CLERK",900.0,0.0);
Emp eb = new Emp(1235,"Acan", "MANAGER",4000.0,9.0);
Emp ec = new Emp(1236,"Dramatic","PRESIDENT",9000.0,80.0);
ea.setMgr(eb);
eb.setMgr(ec);
ea.setDept(dept);
eb.setDept(dept);
ec.setDept(dept);
dept.setEmp(new Emp[]{ea,eb,ec});
System.out.println(ea.getInfo());
System.out.println("\t|-" + ea.getMgr().getInfo());
System.out.println("\t|-" + ea.getDept().getInfo());
System.out.println("-----------------------------------------");
System.out.println(dept.getInfo());
for(int x = 0; x < dept.getEmp().length; x++){
System.out.println("\t|-" + dept.getEmp()[x].getInfo());
if(dept.getEmp()[x].getMgr() != null){
System.out.println("\t\t|-" + dept.getEmp()[x].getMgr().getInfo());
}
}
}
}