// A user interface used once yearly updates the set of Module objects in the // system and updates the lecturer field of each. Name is only set on object // creation. Description may be updated by the lecturer. import java.util.*; public class Module { public Module() {} public Module (String aname, String adescription, Lecturer alecturer) { name = aname; description = adescription; lecturer = alecturer; } public void setLecturer (Lecturer l) { lecturer = l; } // Assumed process: a lecturer who wants to update the description must check // it out by a certain date. If they do not do so, it is assumed that no // changes are needed. public String checkOutDescription (Lecturer l) { String description = ""; if (l == lecturer) { descriptionUpToDate = false; } else { System.out.println ("Sorry, only the lecturer can upate the module description"); } return description; } public void checkInDescription (Lecturer l, String newDescription) { if (l == lecturer) { description = newDescription; descriptionUpToDate = true; } else { System.out.println ("Sorry, only the lecturer can upate the module description"); } } public boolean isUpToDate () {return descriptionUpToDate;} // Hackish thing just to make sure HashSet with Modules in doesn't get // upset when their lecturer fields change. Should be futureproofed. public boolean equals (Object o) { try{ if (o.getClass() == Class.forName("Module")) { return ((Module)o).name == name; } else return false; } catch (java.lang.ClassNotFoundException e) { //Panic: you can see this can't happen. return false; } } public void registerStudent (Student s) { students.put(s.name, s); } public void deregisterStudent (Student s) { students.remove(s.name); } public String makeStudentList() { Iterator i = students.keySet().iterator(); String str = "Class list for module "+name+"\n"; while (i.hasNext()) { Student s = (Student)i.next(); str = str + s.name + "\n"; } return str; } String name; String description; Lecturer lecturer; private boolean descriptionUpToDate = true; private HashMap students = new HashMap(); }