<?php /*PLEASE DO NOT EDIT THIS CODE*/ /*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/ class Mentor { //------------------------ // MEMBER VARIABLES //------------------------ //Mentor Attributes private $name; //Mentor Associations private $students; //------------------------ // CONSTRUCTOR //------------------------ public function __construct($aName) { $this->name = $aName; $this->students = array(); } //------------------------ // INTERFACE //------------------------ public function setName($aName) { $wasSet = false; $this->name = $aName; $wasSet = true; return $wasSet; } public function getName() { return $this->name; } public function getStudent_index($index) { $aStudent = $this->students[$index]; return $aStudent; } public function getStudents() { $newStudents = $this->students; return $newStudents; } public function numberOfStudents() { $number = count($this->students); return $number; } public function hasStudents() { $has = $this->numberOfStudents() > 0; return $has; } public function indexOfStudent($aStudent) { $wasFound = false; $index = 0; foreach($this->students as $student) { if ($student->equals($aStudent)) { $wasFound = true; break; } $index += 1; } $index = $wasFound ? $index : -1; return $index; } public function isNumberOfStudentsValid() { $isValid = $this->numberOfStudents() >= self::minimumNumberOfStudents() && $this->numberOfStudents() <= self::maximumNumberOfStudents(); return $isValid; } public static function requiredNumberOfStudents() { return 4; } public static function minimumNumberOfStudents() { return 4; } public static function maximumNumberOfStudents() { return 4; } public function addStudent($aStudent) { $wasAdded = false; if ($this->indexOfStudent($aStudent) !== -1) { return false; } if ($this->numberOfStudents() >= self::maximumNumberOfStudents()) { return $wasAdded; } $this->students[] = $aStudent; if ($aStudent->indexOfMentor($this) != -1) { $wasAdded = true; } else { $wasAdded = $aStudent->addMentor($this); if (!$wasAdded) { array_pop($this->students); } } return $wasAdded; } public function removeStudent($aStudent) { $wasRemoved = false; if ($this->indexOfStudent($aStudent) == -1) { return $wasRemoved; } if ($this->numberOfStudents() <= self::minimumNumberOfStudents()) { return $wasRemoved; } $oldIndex = $this->indexOfStudent($aStudent); unset($this->students[$oldIndex]); if ($aStudent->indexOfMentor($this) == -1) { $wasRemoved = true; } else { $wasRemoved = $aStudent->removeMentor($this); if (!$wasRemoved) { $this->students[$oldIndex] = $aStudent; ksort($this->students); } } $this->students = array_values($this->students); return $wasRemoved; } public function setStudents($newStudents) { $wasSet = false; $verifiedStudents = array(); foreach ($newStudents as $aStudent) { if (array_search($aStudent,$verifiedStudents) !== false) { continue; } $verifiedStudents[] = $aStudent; } if (count($verifiedStudents) != count($newStudents) || count($verifiedStudents) < self::minimumNumberOfStudents() || count($verifiedStudents) > self::maximumNumberOfStudents()) { return $wasSet; } $oldStudents = $this->students; $this->students = array(); foreach ($verifiedStudents as $aNewStudent) { $this->students[] = $aNewStudent; $removeIndex = array_search($aNewStudent,$oldStudents); if ($removeIndex !== false) { unset($oldStudents[$removeIndex]); $oldStudents = array_values($oldStudents); } else { $aNewStudent->addMentor($this); } } foreach ($oldStudents as $anOldStudent) { $anOldStudent->removeMentor($this); } $wasSet = true; return $wasSet; } public function equals($compareTo) { return $this == $compareTo; } public function delete() { $copyOfStudents = $this->students; $this->students = array(); foreach ($copyOfStudents as $aStudent) { if ($aStudent->numberOfMentors() <= Student::minimumNumberOfMentors()) { $aStudent->delete(); } else { $aStudent->removeMentor($this); } } } } ?> <?php /*PLEASE DO NOT EDIT THIS CODE*/ /*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/ class Student { //------------------------ // MEMBER VARIABLES //------------------------ //Student Attributes private $number; //Student Associations private $mentors; //------------------------ // CONSTRUCTOR //------------------------ public function __construct($aNumber) { $this->number = $aNumber; $this->mentors = array(); } //------------------------ // INTERFACE //------------------------ public function setNumber($aNumber) { $wasSet = false; $this->number = $aNumber; $wasSet = true; return $wasSet; } public function getNumber() { return $this->number; } public function getMentor_index($index) { $aMentor = $this->mentors[$index]; return $aMentor; } public function getMentors() { $newMentors = $this->mentors; return $newMentors; } public function numberOfMentors() { $number = count($this->mentors); return $number; } public function hasMentors() { $has = $this->numberOfMentors() > 0; return $has; } public function indexOfMentor($aMentor) { $wasFound = false; $index = 0; foreach($this->mentors as $mentor) { if ($mentor->equals($aMentor)) { $wasFound = true; break; } $index += 1; } $index = $wasFound ? $index : -1; return $index; } public function isNumberOfMentorsValid() { $isValid = $this->numberOfMentors() >= self::minimumNumberOfMentors() && $this->numberOfMentors() <= self::maximumNumberOfMentors(); return $isValid; } public static function requiredNumberOfMentors() { return 3; } public static function minimumNumberOfMentors() { return 3; } public static function maximumNumberOfMentors() { return 3; } public function addMentor($aMentor) { $wasAdded = false; if ($this->indexOfMentor($aMentor) !== -1) { return false; } if ($this->numberOfMentors() >= self::maximumNumberOfMentors()) { return $wasAdded; } $this->mentors[] = $aMentor; if ($aMentor->indexOfStudent($this) != -1) { $wasAdded = true; } else { $wasAdded = $aMentor->addStudent($this); if (!$wasAdded) { array_pop($this->mentors); } } return $wasAdded; } public function removeMentor($aMentor) { $wasRemoved = false; if ($this->indexOfMentor($aMentor) == -1) { return $wasRemoved; } if ($this->numberOfMentors() <= self::minimumNumberOfMentors()) { return $wasRemoved; } $oldIndex = $this->indexOfMentor($aMentor); unset($this->mentors[$oldIndex]); if ($aMentor->indexOfStudent($this) == -1) { $wasRemoved = true; } else { $wasRemoved = $aMentor->removeStudent($this); if (!$wasRemoved) { $this->mentors[$oldIndex] = $aMentor; ksort($this->mentors); } } $this->mentors = array_values($this->mentors); return $wasRemoved; } public function setMentors($newMentors) { $wasSet = false; $verifiedMentors = array(); foreach ($newMentors as $aMentor) { if (array_search($aMentor,$verifiedMentors) !== false) { continue; } $verifiedMentors[] = $aMentor; } if (count($verifiedMentors) != count($newMentors) || count($verifiedMentors) < self::minimumNumberOfMentors() || count($verifiedMentors) > self::maximumNumberOfMentors()) { return $wasSet; } $oldMentors = $this->mentors; $this->mentors = array(); foreach ($verifiedMentors as $aNewMentor) { $this->mentors[] = $aNewMentor; $removeIndex = array_search($aNewMentor,$oldMentors); if ($removeIndex !== false) { unset($oldMentors[$removeIndex]); $oldMentors = array_values($oldMentors); } else { $aNewMentor->addStudent($this); } } foreach ($oldMentors as $anOldMentor) { $anOldMentor->removeStudent($this); } $wasSet = true; return $wasSet; } public function equals($compareTo) { return $this == $compareTo; } public function delete() { $copyOfMentors = $this->mentors; $this->mentors = array(); foreach ($copyOfMentors as $aMentor) { if ($aMentor->numberOfStudents() <= Mentor::minimumNumberOfStudents()) { $aMentor->delete(); } else { $aMentor->removeStudent($this); } } } } ?>