-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.py
More file actions
128 lines (104 loc) · 3.84 KB
/
Copy pathCourse.py
File metadata and controls
128 lines (104 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"""
File: Course.py
Description: This module defines the Course class, representing a university course that students
can enrol in. It tracks course details such as ID, term, instructor, and enrolled students.
Author: Anush Shirantha De Costa
ID: 110454712
Username: deyay064
This is my own work as defined by the University's Academic Misconduct Policy.
"""
class Course:
"""
Represents a university course with a limited enrolment capacity.
Stores course details and manages student enrolments and instructor assignments.
"""
MAX_CAPACITY = 10
def __init__(self, course_id, course_name, term, unit_count, instructor=None):
"""
Initializes a Course instance with key course details.
:param course_id: Unique identifier for the course (e.g., "COMP1048")
:param course_name: Full name of the course (e.g., "Object-Oriented Programming")
:param term: The academic term this course is offered in (e.g., "SP3 2025")
:param unit_count: Number of credit units the course is worth
:param instructor: Instructor object (Staff) or None
"""
self.__course_id = course_id
self.__course_name = course_name
self.__term = term
self.__unit_count = unit_count
self.__instructor = instructor
self.__enrolled_students = []
def enrol_student(self, student):
"""
Enrols a student in the course roster if capacity allows,
and they are not already enrolled.
:param student: Student object to be enrolled
:return: None
"""
if len(self.__enrolled_students) >= Course.MAX_CAPACITY:
return
elif student in self.__enrolled_students:
return
else:
self.__enrolled_students.append(student)
def drop_student(self, student):
"""
Removes a student from the course roster if present.
:param student: Student object to remove
:return: None
"""
if student in self.__enrolled_students:
self.__enrolled_students.remove(student)
return
else:
return
def get_course_id(self):
"""
Returns the course's unique identifier.
:return: Course ID as a string
"""
return self.__course_id
def get_course_name(self):
"""
Returns the name of the course.
:return: Course name as a string
"""
return self.__course_name
def get_term(self):
"""
Returns the academic term this course is offered in.
:return: Term as a string
"""
return self.__term
def get_instructor(self):
"""
Returns the instructor assigned to the course.
:return: Staff object or None
"""
return self.__instructor
def set_instructor(self, instructor):
"""
Sets the instructor for the course.
:param instructor: Staff object to assign as lead instructor
:return: None
"""
self.__instructor = instructor
def get_enrolled_students(self):
"""
Returns the list of students enrolled in the course.
:return: List of Student objects
"""
return self.__enrolled_students
def __str__(self):
"""
Returns the course name and term, and the assigned instructor’s name and ID if present.
:return: Formatted string with course details
"""
header = f"{self.__course_name} ({self.__term})"
if not self.__instructor:
instructor_line = "Instructor: No Instructor Assigned"
else:
instructor_name = self.__instructor.get_full_name()
eid = self.__instructor.get_employee_id()
instructor_line = f"Instructor: {instructor_name} (ID: {eid})"
return f"{header}\n{instructor_line}"