import java.util.ArrayList; import java.util.List; class Professor { private final String id; private final String name; public Professor(String id, String name) { this.id = id; this.name = name; } public String getId() { return id; } public String getName() { return name; } } class Department { private final String name; private final List professors = new ArrayList<>(); public Department(String name) { this.name = name; } public List getProfessors() { return professors; } public void addProfessor(Professor professor) { professors.add(professor); } public String getName() { return name; } } public class Example02 { public static void main(String[] args) { // --- Professors exist independently of any department --- Professor prof1 = new Professor("P001", "Dr. Alice"); Professor prof2 = new Professor("P002", "Dr. Bob"); Professor prof3 = new Professor("P003", "Dr. Carol"); // --- Create a department and aggregate professors --- Department csDept = new Department("Computer Science Department"); csDept.addProfessor(prof1); csDept.addProfessor(prof2); csDept.addProfessor(prof3); System.out.println("Professors in " + csDept.getName() + ":"); for (Professor prof : csDept.getProfessors()) { System.out.println("- " + prof.getName()); } // --- Department is dissolved (aggregation: professors remain alive) --- csDept = null; System.out.println("\nDepartment dissolved."); // --- Professors still exist --- System.out.println("Professors still employed by the university:"); System.out.println("- " + prof1.getName()); System.out.println("- " + prof2.getName()); System.out.println("- " + prof3.getName()); // --- Professors could be reassigned to another department --- Department mathDept = new Department("Mathematics Department"); mathDept.addProfessor(prof1); System.out.println("\n" + prof1.getName() + " reassigned to " + mathDept.getName()); } }