/* * ==================================================================== * SimSchool.java: Simulate many-to-many relationships between students * and the departments in which they enroll. * ==================================================================== */ import java.util.List; public class SimSchool { public static void main( String[] args ) { // Create student objects ... Student student01 = new Student(); student01.setName("Joe"); Student student02 = new Student(); student02.setName("Jill"); Student student03 = new Student(); student03.setName("David"); Student student04 = new Student(); student04.setName("Scott"); // Add students to civil and environmental engineering ... Department civil = new Department(); civil.setName("CEE"); civil.addStudent( student01 ); civil.addStudent( student02 ); // Add students to electrical and computer engineering ... Department eecs = new Department(); eecs.setName("ECE"); eecs.addStudent( student01 ); eecs.addStudent( student03 ); eecs.addStudent( student04 ); // Print details of student-department assocations ... System.out.println( "Part 1: Summary of Student-Department Associations" ); System.out.println( "==================================================" ); System.out.println( student01 ); System.out.println( student02 ); System.out.println( student03 ); System.out.println( student04 ); // Print details of department-student assocations ... System.out.println( "Part 2: Summary of Department-Student Associations" ); System.out.println( "==================================================" ); System.out.println( civil ); System.out.println( eecs ); // David drop out of EECS to concentrate on CEE ... System.out.println( "Part 3: David switches from ECE to CEE" ); System.out.println( "===============================================" ); student03.removeDepartment( eecs ); student03.addDepartment( civil ); // Validate David's enrollment in CEE and ECE ... System.out.println( student03 ); System.out.println( civil ); System.out.println( eecs ); } }