def remove(self, Student): ''' removes a student based on it's object. uses removeById method input: Student - the object to be removed no output ''' if self.findById(Student.getID()) == None: raise StudentError("Student ID not found; cannot delete") else: return (self.removeById(Student.getID()))
def testStudentRepo(self): a = Student("2", "John", 100) b = StudentRepo() assert len(b) == 0 b.add(a) assert len(b) == 1 a = Student("3", "Picks", 50) b.add(a) assert len(b) == 2 b.remove(a) assert len(b) == 1 b.add(a) assert b.findById("3").getName() == "Picks"
def findGradeByAssign(self, Student, listAssign): ''' finds grade of each student by his assignments ''' for counter in range(0, len(listAssign)): if Student.getID() == listAssign[counter].getID(): return listAssign[counter].getGrade()
def testLinkClass(self): a = Assignment("1", "hello", "world", 1, 1) b = Student("3", "Picks", 50) newlinkid = 3 c = Link(b, a, newlinkid) assert c.getStud().getID() == '3' assert c.getAssign().getKeyID() == 1 assert c.getID() == 3
def findIndex(self, Student): ''' finds the index of the Student object output: the index in the repository (of the Student object) ''' for counter in range(0, len(self)): if self._data[counter].getID() == Student.getID(): return counter
def add(self, Student): ''' adds a new student to the repository input: Student object ''' if self.findById(Student.getID()) != None: raise StudentError("Duplicate ID") else: self._data.append(Student)
def readfromfile(self): ''' loads the repository from the file ''' f = open("stud.txt", "r") raw = f.readline().split(sep=";") while raw[0] != "end\n" and raw[0] != "end" and len(raw) >= 3: newid = raw[0] newname = raw[1] newgroup = int(raw[2]) newstud = Student(newid, newname, newgroup) self.add(newstud) raw = f.readline().split(sep=";")
def addStud(self): ''' adds a new student to the repository calls add function in the repository ''' print("Student Name:") tempName = input() print("Student ID:") tempID = input() print("Student Group:") try: tempGroup = int(input()) except: raise StudentError("Invalid group!") newStud = Student(tempID, tempName, tempGroup) self._studrepo.add(newStud) self._undoop.append(AddOperation(newStud)) self._redoop = []
def testStudentClass(self): a = Student("1", "Joe", 916) #real professional testing right here, folks. assert a.getID() == "1" assert a.getName() == "Joe" assert a.getGroup() == 916 a.setGroup(69) a.setID("69") a.setName("Bob") assert a.getID() == "69" assert a.getName() == "Bob" assert a.getGroup() == 69