Exemple #1
0
 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()))
Exemple #2
0
 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"
Exemple #3
0
 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()
Exemple #4
0
 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
Exemple #5
0
    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
Exemple #6
0
 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)
Exemple #7
0
 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=";")
Exemple #8
0
 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 = []
Exemple #9
0
 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