|
public class Testdemo {
public static void Main (String args[]) {
First level: Setting up relationships
1. Set each object entity separately, no connection between each other
EMP ea = new EMP (7369, "SMITH", "clerk", 800.0,0.0);
EMP EB = new emp (7902, "FORD", "MANAGER", 2450.0,0.0);
EMP EC = new EMP (7839, "KING", "President", 5000.0,0.0);
Dept Dept = new Dept ("ACCOUNTING", "New York");
2. Setting up employees and leadership relationships
Ea.setmgr (EB);
Eb.setmgr (EC); EC does not lead
3. Set up employee and departmental relationships
Ea.setdept (dept); Employees and Departments
Eb.setdept (dept); Employees and Departments
Ec.setdept (dept); Employees and Departments
EMP [] temp = new emp[] {EA,EB,EC};
Dept.setemps (temp);
Second level: Take data based on relationship
1. Remove Department information
System.out.println (Dept.getinfo ());
2. Remove all employee information from the department
EMP [] allemps = Dept.getemps (); Receive first
for (int x = 0; x < allemps.length; x + +) {
Emp e = allemps[x]; Take out an employee
System.out.println ("\ T" + e.getinfo ());
if (e.getmgr () = null) {//has a leader
System.out.println ("\t\t|-" + e.getmgr (). GetInfo ());
}
}
3, according to employees to take information
System.out.println (Ea.getinfo ());
if (ea.getmgr () = null) {
System.out.println (Ea.getmgr (). GetInfo ());
}
if (ea.getdept () = null) {
System.out.println (Ea.getdept (). GetInfo ());
}
}
}
|