module MainCourseDB; export CourseDB; object CourseDB is components: Course*; operations: SelectCourse, SaveCourse, DeleteCourse, NewCourse, AddCourse; description: (* The main course database that contains all courses offered by the department, and information about each *); end CourseDB; object Course is components: title:Title and prefix:Prefix and number:Number and units:Units and max:MaxStudents and secs:Sections and lecture:IsLecture and lab:IsLab and smart:IsSmartroom; description: (* The basic object for a Room and its related information *); end Course; object Title is string description: (* The name of the class *); end; object Prefix is string description: (* The three or four letter course prefix (E.g. CSC, CPE) *); end; object Number is integer description: (* Actual course number within the department *); end; object Units is integer description: (* Number of units the course is worth for the students *); end; object MaxStudents is integer description: (* Maximum number of students that can take the class *); end; object Sections is integer description: (* Number of sections of this course requires to meet demand of the students *); end; object IsLecture is boolean description: (* True if the course is a lecture course *); end; object IsLab is boolean description: (* True if the course is a lab course *); end; object IsSmartroom is boolean description: (* True if the course requires a room with "SmartRoom" capabilities *); end; operation SaveCourse is inputs: cDB:CourseDB, selected:Course, new:Course; outputs: cDB':CourseDB; description: (* Saves the given course to the course database. If the course already exists, it updates any fields that have been changed. If the course does not exist, then it adds it to the list of courses as a brand new entry. *); precondition: (* * There should be a course selected from the list, the one that you * are actually updating! *) (selected != nil) (* * The fields containing the information about the course cannot be * empty -- the booleans are excluded from this list because empty * values still contain information about the course *) and (new.title != nil) and (new.prefix != nil) and (new.number != nil) and (new.units != nil) and (new.max != nil) and (new.secs != nil); postcondition: (* * When the record is found in the database, you replace everything * about that record with the information from the new record *) forall (cr':Course) if (cr' = selected) then (cr' = new) (* * The new course is added to the database if and only if the course * being added is the newly changed course, or if it exists already in * the database and is NOT being replaced by the updated course. *) and forall (cr':Course) ((cr' in cDB') iff (((cr' = new) or ((cr' in cDB) and (cr' != selected))) and cr' != selected)); end SaveCourse; operation DeleteCourse is inputs: cDB:CourseDB, selected:Course; outputs: cDB':CourseDB; description: (* Deletes the selected course from the database. The selected course is determined by the highlighted entry in the GUI. The entry is simply removed from the input database, and a database without that entry is output back to the program. *); precondition: (* * The given course is actually in the course database *) selected in cDB; postcondition: (* * All the courses are put into the database if and only if they currently * exist in the database and they are not the course that is being deleted *) forall (cr':Course) (cr' in cDB') iff ((cr' in cDB) and (cr' != selected)); end DeleteCourse; operation AddCourse is inputs: new:Course, cDB:CourseDB; outputs: cDB':CourseDB; description: (* Adds a new course to the database. Information is gathered from the GUI screen and compiled into the input course object. The course is added to the list of courses in the course database. The newly added course must be added using the 'Add' button on the GUI. This operation is NOT used to update previously existing courses. *); precondition: (* * The fields in the input course are not empty. Once again, the booleans * can be empty, because it still conveys information about the course *) (new.title != nil) and (new.prefix != nil) and (new.number != nil) and (new.units != nil) and (new.max != nil) and (new.secs != nil) (* * There cannot be any courses in the database with the same course prefix * and number. If the user wishes to update a course, then he or she must * select a course from the list using the user interface and use the * ChangeCourse operation by pressing the 'Save' button *) and (not (exists (cr' in cDB) ((cr'.prefix = new.prefix) and (cr'.number = new.number)))); postcondition: (* * The course is added to the database if and only if it previously exists * in the database or if it is the course being added. *) forall (cr':Course) (cr' in cDB') iff ((cr' = new) or (cr' in cDB)); end AddCourse; end MainCourseDB;