5.6 Course Database FSML
module CourseDB;
export CourseDB;
object CourseDB
components: CourseEntry*;
operations: AddEntry, RemoveEntry, ChangeEntry;
description: (*
The CourseDB is the database for each schedule. It contains all
of the avaiable courses.
*);
end;
object CourseEntry
components: coursedepartment:CourseDepartment and coursenumber:CourseNumber and coursename:CourseName and coursetype:CourseType and
coursemaxenroll:CourseMaxEnroll and courselabpairing:CourseLabPairing and coursewtus:CourseWTUs and courseequipment:CourseEquipment and
coursedescription:CourseDescription;
description: (*
A Course entry contains a department, course number, course name,
type, maximum enrollment, lab pairing, WTUs, required equipment,
and a description
*);
end;
object CourseName = string;
object CourseDepartment = string;
object CourseType = Lecture or Lab;
object Lecture = string and boolean;
object Lab = string;
object CourseMaxEnroll = integer;
object CourseWTUs = integer;
object CourseEquipment = string;
object CourseDescription = string;
object CourseNumber = integer;
object CourseLabPairing = boolean;
operation AddEntry
inputs: cdb:CourseDB, ce:CourseEntry;
outputs: cdb':CourseDB;
description: (* This operation adds a course entry to the course
database.*);
precondition:
(*
* There is no user record in the input CourseDB with the same Department and Course Number as the
* record to be added. The Department, Course Number, and WTUs must not be empty.
*)
(not (exists (ce' in cdb) ce'.coursedepartment = ce.coursedepartment and ce'.coursenumber = ce.coursenumber))
and
ce.coursedepartment != nil and ce.coursenumber != nil and ce.coursewtus != nil;
postcondition:
(*
* There is no user record in the input CourseDB with the same Department and Course Number as the
* record to be added.
*
* A course entry is in the output db if and only if it is the new
* record to be added or it is in the input db.
*)
forall (ce':CourseEntry)
(ce' in cdb') iff ((ce' = ce) or (ce' in cdb));
end;
operation RemoveEntry
inputs: cdb:CourseDB, ce:CourseEntry;
outputs: cdb':CourseDB;
description: (* This operation removes a course entry from the course
database by department and number.*);
precondition: (* The entry is in the database*)
(ce in cdb);
postcondition: (* The entry is not in the database, but all other entries are still there *)
(forall (ce':CourseEntry)
(ce' in cdb') iff ((ce' != ce) and (ce' in cdb)));
end;
operation ChangeEntry
inputs: cdb:CourseDB, oldCE:CourseEntry, newCE:CourseEntry;
outputs: cdb':CourseDB;
description: (* This operation removes the old entry and adds a new entry to the database.*);
precondition: (* Old entry must exist in the database, don't care if the new entry is the same as the old one.*)
(oldCE in cdb) and newCE.coursedepartment != nil and newCE.coursenumber != nil and newCE.coursewtus != nil;
postcondition:
(*The old entry does not exist and the new entry does exist*)
(newCE in cdb') and not(oldCE in cdb');
end;
end CourseDB;
Prev: Preferences FMSL
| Next: Schedule Entry FMSL
| Up: Specs
| Top: index