2 (3)g
2 (3)g
Scenario:
Create a School Management System where a School has multiple Students and employs
multiple Teachers. However, a Student can exist independently of a School (e.g., if they
transfer).
Class Descriptions:
1. School
○ Attributes: schoolName, location
○ Methods: addStudent(), removeStudent(), hireTeacher(),
displayDetails()
2. Student (Aggregated by School)
○ Attributes: name, studentID, grade
○ Methods: getStudentDetails(), enrollInSubject()
3. Teacher (Associated with School, but independent)
○ Attributes: name, teacherID, subject
○ Methods: teach(), evaluateStudent()
Aggregation Relationship:
● School aggregates multiple Students (hollow diamond).
● School associates with multiple Teachers (not aggregation since a Teacher can work
elsewhere).
Problem 2: Association – Student and Course
Problem Statement:
A Student can enroll in multiple Courses, and a Course can have multiple Students. This is a
classic example of a Many-to-Many Association between Student and Course.
Explanation:
● In Association, two or more objects are related but can exist independently.
● Here, a Student can enroll in multiple Courses without being dependent on a single
course.
● Similarly, a Course can have multiple Students, but it still exists even if no students
enroll.
UML Diagram:
+-----------+ (enrolls in) +-----------+
| Student |-------------------------->| Course |
+-----------+ (has students) +-----------+
| |
| * * |
--------------------------------------
(Many-to-Many)