Exemple #1
0
    def __init__(self, discipline, id, teacher, grade):
        """
         Creates a new instance of Grade.
        """
        self.__discipline = discipline
        if id < 0:
            raise StudentException("ID cannot be negative")
        if grade < 0 or grade > 10:
            raise StudentException("The grade must between 0 and 10")

        self.__id = id
        self.__discipline = discipline
        self.__teacher = teacher
        self.__grade = grade
Exemple #2
0
 def setId(self, value):
     '''
     Setter for id
     '''
     if value < 0:
         raise StudentException("Id must be positive")
     self.__id = value
Exemple #3
0
 def setGrade(self, value):
     '''
     Setter for grade
     '''
     if value < 0 or value > 10:
         raise StudentException("Grade must be between 0 and 10")
     self.__grade = value
    def removeStudentFromDiscipline(self, discipline, studentID):
        '''
        removes a student from a discipline
        Input: discipline - string, the name of the discipline that the student must be removed from
               studentID - positive integer, the ID of the student to remove from the discipline
        Output: if such a Grade exists, it is removed and returned
        Exceptions: raises DisciplineException if the given discipline's name does not exist in DisciplineRepository
                    raises StudentException if the given student's ID does not exist in StudentRepository
                    raises GradeException if a Grade with the given discipline and studentID does not exist
        '''
        # remove undo indexes
        self.__operations = self.__operations[0:self.__index]

        if self.__disRepo.findByName(discipline) == None:
            raise DisciplineException("There is no Discipline with name " +
                                      discipline + "!")
        if self.__stuRepo.findByID(studentID) == None:
            raise StudentException("The is no Student with ID " +
                                   str(studentID) + "!")

        # get the grade before deleting it
        gra = self.__repo.findByDisciplineAndStudentID(discipline, studentID)

        self.__repo.removeStudentFromDiscipline(discipline, studentID)

        # if no exceptions were raised => record the operation for undo
        self.__operations.append(RemoveOperation(gra))
        self.__index += 1
        self.__undoCtrl.recordUpdatedController([self])
    def updateGrade(self, discipline, studentID, grade):
        '''
        updates a Grade's grade
        Input: discipline - string, the name of the discipline that the student must be added to
               studentID - positive integer, the ID of the student to add to a discipline
               grade - float, 1<= grade <= 10, the grade to be updated
        Output: if such a Grade exists, it is updated
        Exceptions: raises DisciplineException if the given discipline's name does not exist in DisciplineRepository
                    raises StudentException if the given student's ID does not exist in StudentRepository
                    raises GradeException if a Grade with the given discipline and studentID does not exist
        '''
        # remove undo indexes
        self.__operations = self.__operations[0:self.__index]

        if self.__disRepo.findByName(discipline) == None:
            raise DisciplineException("There is no Discipline with name " +
                                      discipline + "!")
        if self.__stuRepo.findByID(studentID) == None:
            raise StudentException("The is no Student with ID " +
                                   str(studentID) + "!")

        # get the grade before update
        oldGrade = deepcopy(
            self.__repo.findByDisciplineAndStudentID(discipline, studentID))

        self.__repo.updateGrade(discipline, studentID, grade)

        # if no exceptions were raised => record the operation for undo
        newGrade = deepcopy(
            self.__repo.findByDisciplineAndStudentID(discipline, studentID))
        self.__operations.append(UpdateOperation(oldGrade, newGrade))
        self.__index += 1
        self.__undoCtrl.recordUpdatedController([self])
    def addStudentToDiscipline(self, discipline, studentID):
        '''
        adds a student to a discipline
        Input: discipline - string, the name of the discipline that the student must be added to
               studentID - positive integer, the ID of the student to add to the discipline
        Output: the given Grade is added, if no other Grade with the same discipline and studentID exists
                ! the given Grade's grade is initialized with 0
        Exceptions: raises DisciplineException if the given discipline's name does not exist in DisciplineRepository
                    raises StudentException if the given student's ID does not exist in StudentRepository
                    raises GradeException if another Grade with the same discipline and studentID already exists            
        '''
        # remove undo indexes
        self.__operations = self.__operations[0:self.__index]

        if self.__disRepo.findByName(discipline) == None:
            raise DisciplineException("There is no Discipline with name " +
                                      discipline + "!")
        if self.__stuRepo.findByID(studentID) == None:
            raise StudentException("The is no Student with ID " +
                                   str(studentID) + "!")
        self.__repo.addStudentToDiscipline(discipline, studentID)

        gra = Grade(discipline, studentID, 0)
        # if no exceptions were raised => record the operation for undo
        self.__operations.append(AddOperation(gra))
        self.__index += 1
        self.__undoCtrl.recordUpdatedController([self])
 def __init__(self,id,name):
     """
      Creates a new instance of Student.
     """
     if id<0:
         raise StudentException("ID must be positive")
     self.__id=id
     self.__name=name
     self.__average=0
Exemple #8
0
 def remove(self, ID):
     '''
     removes a Student from the repository, using its name
     Input: ID, a positive integer denoting the Student that must be updated
     Output: if such a Discipline exists, it is removed
     '''
     indexID = self.__find(ID)
     if indexID == -1:
         raise StudentException("There is no student with ID " + str(ID) + "!")
     self.__data.pop(indexID)
Exemple #9
0
 def add(self, stu):
     '''
     add a Student to the repository
     Input: stu - object of type Student
     Output: the given student is added to the repository, if no other student has the same ID
     Exceptions: raises StudentException if another student with the same name already exists
     '''
     if self.findBysID(stu.getID()) != None:
         raise StudentException("Student with ID: " + str(stu.getID()) + " already exists!")
     self.__data.append(stu)
Exemple #10
0
 def update(self, id, newName):
     '''
     Updates the student with the given id with the new name.
     Input:id-integer positive number
           newName-string
     Raises StudentException if there is no student with the given id.
     '''
     idx = self.__find(id)
     if idx == -1:
         raise StudentException("There is no student with the given ID")
     self.__data[idx].setName(newName)
Exemple #11
0
 def remove(self, id):
     '''
      Removes a student from the base, using its id
      Input: id - integer, the id of the student that must be removed
      Output: if such a student exists, it is removed and returned
      Exceptions: raises StudentException if a student with the given id
     does not exist
      '''
     idx = self.__find(id)
     if idx == -1:
         raise StudentException("There is no student with the given ID")
     return self.__data.pop(idx)
Exemple #12
0
 def add(self, stud):
     '''
      Adds a student to the base.
      Input: stud - object of type Grade
      Output: the given student is added to the base, if no other
     student with the same id exists
      Exceptions: raises StudentException if another student with the
     same id already exists
      '''
     if self.findById(stud.getId()) != None:
         raise StudentException("ID already exists")
     self.__data.append(stud)
 def remove(self, ID):
     '''
     removes a Student from the repository, using its ID
     Input: ID - positive integer, the ID of the Student that must be removed
     Output: if such a Student exists, it is removed and returned
     Exceptions: raises StudentException if a Student with the given ID does not exist
     '''
     indexID = self.__find(ID)
     if indexID == -1:
         raise StudentException("The is no Student with ID " + str(ID) +
                                "!")
     self.__data.pop(indexID)
 def update(self, ID, newName):
     '''
     updates a Student from the repository, using its ID
     Input: ID - positive integer, the ID of the Student that must be updated
            newName - string, updated name of the Student
     Output: if such a Student exists, it is updated
     Exceptions: raises StudentException if a Student with the given ID does not exist
     '''
     indexID = self.__find(ID)
     if indexID == -1:
         raise StudentException("The is no Student with ID " + str(ID) +
                                "!")
     self.__data[indexID].setName(newName)
Exemple #15
0
 def add(self, stud):
     '''
      Adds a grade to the base.
      Input: stud - object of type Grade
      Output: the given Grade is added to the base, if no other
     grade with the same id exists
      Exceptions: raises StudentException if another grade with the
     same id already exists
      '''
     c = self.findById(stud.getId())
     if self.findById(stud.getId()) != None and c.getDiscipline(
     ) == stud.getDiscipline():
         raise StudentException("ID already exists at the same discipline")
     self.__data.append(stud)
Exemple #16
0
    def update(self, id, newGrade, newTeacher, newDiscipline):
        '''
        Updates the grade with the given id with the new grade, new teacher, new discipline.
        Input: id- integer positive number
               newGrade-integer between 0 and 10
               newTeacher-string
               newDiscipline-string
        Raises StudentException if there is no student with the given id.
        '''
        idx = self.__findUpdate(id, newDiscipline)
        if idx == -1:
            raise StudentException(
                "There is no student with the given ID or the student does not have a grade at the given discipline"
            )

        self.__data[idx].setTeacher(newTeacher)
        self.__data[idx].setGrade(newGrade)
        self.__data[idx].setDiscipline(newDiscipline)
    def addGrade(self, grade):
        '''
        adds a grade to the lists of grade
        Input: grade - object of type grade
        Output: the given grade is added, if the given grade is valid
        Exceptions: raises DisciplineExceptions if the given discipline's name does not exist in the Discipline list
                    raises StudentExceptions if the given student's name does not exist in the Student list
        '''
        self.__operations = self.__operations[0:self.__index]

        if self.__disRepo.findBydID(grade.getDisciplineID()) == None:
            raise DisciplineException("There is no discipline with ID " + str(grade.getDisciplineID()) + "!")
        if self.__stuRepo.findBysID(grade.getStudentID()) == None:
            raise StudentException("There is no student with ID " + str(grade.getStudentID()) + "!")

        self.__repo.addGrade(grade, self.__stuRepo, self.__disRepo)

        self.__operations.append(AddOperation(grade))
        self.__index += 1
        self.__undoCtrl.recordUpdatedController([self])