-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamClass.py
More file actions
50 lines (39 loc) · 1.47 KB
/
ExamClass.py
File metadata and controls
50 lines (39 loc) · 1.47 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
class Exam():
def __init__(self,name):
self.name = name
self.examLength = ""
self.room = ""
self._listOfStudents = []
self.numClashesPerSlotDict = {}
self.numStudents = len(self._listOfStudents)
def updateNumStudents(self):
self.numStudents = len(self._listOfStudents)
def addStudent(self, student):
if student.__class__.__name__ == "Student":
self._listOfStudents.append(student)
self.updateNumStudents()
return
raise TypeError("Exam.addStudent: student argument is not an instance of Student:",str(student))
def getExamDetailsDict(self):
return {"name":self.name,
"examLength":self.examLength,
"room":self.room,
"numStudents":self.numStudents}
def toJson(self):
return self.getExamDetailsDict()
def addExamLength(self,examLength):
self.examLength = examLength
def addRoom(self,room):
self.room = room
def getNumClashes(self,exam):
if isinstance(exam,Exam):
clashes = set(self._listOfStudents).intersection(set(exam._listOfStudents))
return len(clashes), None
else:
return None, "parameter supplied is not an Exam object"
def listOfStudentsIsEmpty(self):
if self._listOfStudents == []:
return True
return False
def __str__(self):
return "this object is an instance of 'Exam'"