Project: University Course System
On this page
1. Define the Rules2. Check the Model3. Predict and Run4. Change and Explain5. Separate Responsibilities6. Test and Reconcile7. Extend One FeatureBuild a small University Course System that enrolls students, stores grades and reports results. Use the diagrams and model from the preceding chapters.
The UML activity diagram outlines the baseline verification scenario. Read its actions downward from the start circle to the end bullseye.
1. Define the Rules
Keep one Student per student ID and one Course per course code. Each Enrollment links exactly one of each. Reject repeated enrollment in the same Course object; accept grades A, B, C, D and F, with None before grading.
The core is in memory. Login, persistent storage, capacity limits, prerequisites and recommendations are extensions.
2. Check the Model
Use the class diagram and object snapshot. Confirm that names and associations match the Python definitions. A grade belongs to an Enrollment, not to Course alone.
3. Predict and Run
Run the complete definitions from From Diagram to Code, then this continuation. The standalone project source combines both.
ada = Student("S001", "Ada Lovelace")
cs101 = Course("CS101", "Intro to CS", 6)
enrollment = ada.enroll(cs101)
enrollment.set_grade("A")
print(ada.name, ada.course_codes())
print(cs101.course_code, cs101.student_names())
print("Grade:", enrollment.grade)
try:
ada.enroll(cs101)
except ValueError as error:
print("Rejected:", error)
print("Enrollment links:", len(ada._enrollments), len(cs101._enrollments))Output
Ada Lovelace ['CS101']
CS101 ['Ada Lovelace']
Grade: A
Rejected: Already enrolled
Enrollment links: 1 1
The duplicate request is rejected before changing either list, so the final counts remain one and one.
4. Change and Explain
Add Grace, enroll her in CS101 and assign her grade B. Confirm that Ada’s grade remains A. Reject an invalid grade Z and verify that the earlier value remains unchanged.
For a catalog extension, store courses in a dictionary keyed by code. Reject duplicate codes before creating another course object; the current model detects duplicate enrollment by object identity.
5. Separate Responsibilities
Use the MVC functions and module layout. Keep enrollment rules in the Model, request coordination in the Controller and message formatting in the View.
6. Test and Reconcile
Test empty collections, normal enrollment, duplicate rejection, two students in one course, one student in two courses, grade updates and invalid credits. Rejected operations must preserve state.
Trace the activity and sequence views for success and failure. Update the editable diagrams whenever you change a rule.
7. Extend One Feature
Choose Professor grading, course capacity, prerequisite checks or a local recommendation rule. State its inputs and acceptance examples before coding. Update the affected use cases, data model and components.
Deliver the Python sources, editable diagrams, SVGs and test evidence. Explain one design choice and one remaining limitation.