class Mentor():
    def __init__(self, aName):
        self._pupils = None
        self._name = None
        self._name = aName
        self._pupils = []

    def setName(self, aName):
        wasSet = False
        self._name = aName
        wasSet = True
        return wasSet

    def getName(self):
        return self._name

    def getPupil(self, index):
        aPupil = self._pupils[index]
        return aPupil

    def getPupils(self):
        newPupils = tuple(self._pupils)
        return newPupils

    def numberOfPupils(self):
        number = len(self._pupils)
        return number

    def hasPupils(self):
        has = len(self._pupils) > 0
        return has

    def indexOfPupil(self, aPupil):
        index = (-1 if not aPupil in self._pupils else self._pupils.index(aPupil))
        return index

    def isNumberOfPupilsValid(self):
        isValid = self.numberOfPupils() >= Mentor.minimumNumberOfPupils() and self.numberOfPupils() <= Mentor.maximumNumberOfPupils()
        return isValid

    @staticmethod
    def minimumNumberOfPupils():
        return 5

    @staticmethod
    def maximumNumberOfPupils():
        return 7

    def addPupil1(self, aNumber):
        from Pupil import Pupil
        if self.numberOfPupils() >= Mentor.maximumNumberOfPupils() :
            return None
        else :
            return Pupil(aNumber, self)

    def addPupil2(self, aPupil):
        wasAdded = False
        if (aPupil) in self._pupils :
            return False
        if self.numberOfPupils() >= Mentor.maximumNumberOfPupils() :
            return wasAdded
        existingMentor = aPupil.getMentor()
        isNewMentor = not (existingMentor is None) and not self == existingMentor
        if isNewMentor and existingMentor.numberOfPupils() <= Mentor.minimumNumberOfPupils() :
            return wasAdded
        if isNewMentor :
            aPupil.setMentor(self)
        else :
            self._pupils.append(aPupil)
        wasAdded = True
        return wasAdded

    def removePupil(self, aPupil):
        wasRemoved = False
        if self == aPupil.getMentor() :
            return wasRemoved
        if self.numberOfPupils() <= Mentor.minimumNumberOfPupils() :
            return wasRemoved
        self._pupils.remove(aPupil)
        wasRemoved = True
        return wasRemoved

    def addPupilAt(self, aPupil, index):
        wasAdded = False
        if self.addPupil(aPupil) :
            if index < 0 :
                index = 0
            if index > self.numberOfPupils() :
                index = self.numberOfPupils() - 1
            self._pupils.remove(aPupil)
            self._pupils.insert(index, aPupil)
            wasAdded = True
        return wasAdded

    def addOrMovePupilAt(self, aPupil, index):
        wasAdded = False
        if (aPupil) in self._pupils :
            if index < 0 :
                index = 0
            if index > self.numberOfPupils() :
                index = self.numberOfPupils() - 1
            self._pupils.remove(aPupil)
            self._pupils.insert(index, aPupil)
            wasAdded = True
        else :
            wasAdded = self.addPupilAt(aPupil, index)
        return wasAdded

    def delete(self):
        i = len(self._pupils)
        while i > 0 :
            aPupil = self._pupils[i - 1]
            aPupil.delete()
            i -= 1

    def __str__(self):
        return str(super().__str__()) + "[" + "name" + ":" + str(self.getName()) + "]"

    def addPupil(self, *argv):
        from Pupil import Pupil
        if len(argv) == 1 and isinstance(argv[0], str) :
            return self.addPupil1(argv[0])
        if len(argv) == 1 and isinstance(argv[0], Pupil) :
            return self.addPupil2(argv[0])
        raise TypeError("No method matches provided parameters")


import os

class Pupil():
    def __init__(self, aNumber, aMentor):
        self._mentor = None
        self._number = None
        self._number = aNumber
        didAddMentor = self.setMentor(aMentor)
        if not didAddMentor :
            raise RuntimeError ("Unable to create pupil due to mentor. See http://manual.umple.org?RE002ViolationofAssociationMultiplicity.html")

    def setNumber(self, aNumber):
        wasSet = False
        self._number = aNumber
        wasSet = True
        return wasSet

    def getNumber(self):
        return self._number

    def getMentor(self):
        return self._mentor

    def setMentor(self, aMentor):
        from Mentor import Mentor
        wasSet = False
        if aMentor is None :
            return wasSet
        if aMentor.numberOfPupils() >= Mentor.maximumNumberOfPupils() :
            return wasSet
        existingMentor = self._mentor
        self._mentor = aMentor
        if not (existingMentor is None) and not existingMentor == aMentor :
            didRemove = existingMentor.removePupil(self)
            if not didRemove :
                self._mentor = existingMentor
                return wasSet
        self._mentor.addPupil(self)
        wasSet = True
        return wasSet

    def delete(self):
        placeholderMentor = self._mentor
        self._mentor = None
        if not (placeholderMentor is None) :
            placeholderMentor.removePupil(self)

    def __str__(self):
        return str(super().__str__()) + "[" + "number" + ":" + str(self.getNumber()) + "]" + str(os.linesep) + "  " + "mentor = " + ((format(id(self.getMentor()), "x")) if not (self.getMentor() is None) else "null")