Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Person
- {
- public $name;
- public $company;
- public $car;
- public $pokemon;
- public $parents;
- public $children;
- /**
- * Person constructor.
- * @param $company
- * @param $car
- * @param $pokemon
- * @param $parents
- * @param $children
- */
- public function __construct($name = '', $company = '', $car = '', $pokemon = '', $parents = '', $children = '')
- {
- $this->name = $name;
- $this->company = $company;
- $this->car = $car;
- $this->pokemon = $pokemon;
- $this->parents = $parents;
- $this->children = $children;
- }
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * @return object
- */
- public function getCompany()
- {
- return $this->company;
- }
- /**
- * @return object
- */
- public function getCar()
- {
- return $this->car;
- }
- /**
- * @return object
- */
- public function getPokemon()
- {
- return $this->pokemon;
- }
- /**
- * @return object
- */
- public function getParents()
- {
- return $this->parents;
- }
- /**
- * @return string
- */
- public function getChildren()
- {
- return $this->children;
- }
- /**
- * @param string $name
- */
- public function setName(string $name)
- {
- $this->name = $name;
- }
- /**
- * @param Company $company
- */
- public function setCompany(Company $company)
- {
- $this->company = $company;
- }
- /**
- * @param Car $car
- */
- public function setCar(Car $car)
- {
- $this->car = $car;
- }
- /**
- * @param Pokemon $pokemon
- */
- public function setPokemon(Pokemon $pokemon)
- {
- $this->pokemon = $pokemon;
- }
- /**
- * @param Parents $parents
- */
- public function setParents(Parents $parents)
- {
- $this->parents = $parents;
- }
- /**
- * @param Children $children
- */
- public function setChildren(Children $children)
- {
- $this->children = $children;
- }
- }
- class Company
- {
- public $name;
- public $department;
- public $salary;
- /**
- * Company constructor.
- * @param $name
- * @param $department
- * @param $salary
- */
- public function __construct($name = '', $department = '', $salary = '')
- {
- $this->name = $name;
- $this->department = $department;
- $this->salary = $salary;
- }
- /**
- * @return string
- */
- public function getName(): string
- {
- return $this->name;
- }
- /**
- * @return string
- */
- public function getDepartment(): string
- {
- return $this->department;
- }
- /**
- * @return string
- */
- public function getSalary(): string
- {
- return $this->salary;
- }
- }
- class Pokemon
- {
- public $name;
- public $element;
- /**
- * Pokemon constructor.
- * @param $name
- * @param $element
- */
- public function __construct($name = '', $element = '')
- {
- $this->name = $name;
- $this->element = $element;
- }
- /**
- * @return string
- */
- public function getName(): string
- {
- return $this->name;
- }
- /**
- * @return string
- */
- public function getElement(): string
- {
- return $this->element;
- }
- }
- class Parents
- {
- public $name;
- public $birthday;
- /**
- * Parents constructor.
- * @param $name
- * @param $birthday
- */
- public function __construct($name = '', $birthday = '')
- {
- $this->name = $name;
- $this->birthday = $birthday;
- }
- /**
- * @return string
- */
- public function getName(): string
- {
- return $this->name;
- }
- /**
- * @return string
- */
- public function getBirthday(): string
- {
- return $this->birthday;
- }
- }
- class Children
- {
- public $name;
- public $birthday;
- /**
- * Children constructor.
- * @param $name
- * @param $birthday
- */
- public function __construct($name = '', $birthday = '')
- {
- $this->name = $name;
- $this->birthday = $birthday;
- }
- /**
- * @return string
- */
- public function getName(): string
- {
- return $this->name;
- }
- /**
- * @return string
- */
- public function getBirthday(): string
- {
- return $this->birthday;
- }
- }
- class Car
- {
- public $model;
- public $speed;
- /**
- * Car constructor.
- * @param $model
- * @param $speed
- */
- public function __construct($model = '', $speed = '')
- {
- $this->model = $model;
- $this->speed = $speed;
- }
- /**
- * @return string
- */
- public function getModel(): string
- {
- return $this->model;
- }
- /**
- * @return string
- */
- public function getSpeed(): string
- {
- return $this->speed;
- }
- }
- $persons = [];
- while (true) {
- $inputLine = trim(fgets(STDIN));
- if ($inputLine == 'End') {
- break;
- }
- $inputLine = explode(' ', $inputLine);
- $personName = $inputLine[0];
- $class = $inputLine[1];
- if (!in_array($personName, $persons)) {
- $person = new Person($personName);
- }
- switch ($class) {
- case 'pokemon':
- $pokemonName = $inputLine[2];
- $pokemonElement = $inputLine[3];
- $pokemon = new Pokemon($pokemonName, $pokemonElement);
- $person->setPokemon($pokemon);
- break;
- case 'parents':
- $parentsName = $inputLine[2];
- $parentBirthday = $inputLine[3];
- $parents = new Parents($parentsName, $parentBirthday);
- $person->setParents($parents);
- break;
- case 'company':
- $companyName = $inputLine[2];
- $companyDepartment = $inputLine[3];
- $companySalary = $inputLine[4];
- $company = new Company($companyName, $companyDepartment, $companySalary);
- $person->setCompany($company);
- break;
- case 'children':
- $childrenName = $inputLine[2];
- $childrenBirthday = $inputLine[3];
- $children = new Children($childrenName, $childrenBirthday);
- $person->setChildren($children);
- break;
- case 'car':
- $carModel = $inputLine[2];
- $carSpeed = $inputLine[3];
- $car = new Car($carModel, $carSpeed);
- $person->setCar($car);
- break;
- }
- if (!in_array($personName, $persons)) {
- $persons[$personName] = $person;
- }
- }
- $personOutput = trim(fgets(STDIN));
- $person = $persons[$personOutput];
- var_dump($persons); exit;
- echo $personOutput . PHP_EOL . 'Company: ' . PHP_EOL .
- (is_object($person->getCompany()) ? $person->getCompany()->getName() : '') . PHP_EOL .
- 'Car: ' . PHP_EOL .
- (is_object($person->getCar()) ? $person->getCar()->getModel() : '') . PHP_EOL .
- 'Pokemon: ' . PHP_EOL .
- (is_object($person->getPokemon()) ? $person->getPokemon()->getName() : '') . PHP_EOL .
- 'Parents: ' . PHP_EOL .
- (is_object($person->getParents()) ? $person->getParents()->getName() : '') . PHP_EOL .
- 'Children: ' . PHP_EOL;
- (is_object($person->getChildren()) ? $person->getChildren()->getName() : '') . PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement