Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Company
- {
- /**
- * @var string
- */
- private $companyName;
- /**
- * @var string
- */
- private $department;
- /**
- * @var float
- */
- private $salary;
- public function __construct(string $companyName, string $department, float $salary)
- {
- $this->companyName = $companyName;
- $this->department = $department;
- $this->salary = $salary;
- }
- /**
- * @return string
- */
- public function getCompanyName(): string
- {
- return $this->companyName;
- }
- /**
- * @param string $companyName
- */
- public function setCompanyName(string $companyName): void
- {
- $this->companyName = $companyName;
- }
- /**
- * @return string
- */
- public function getDepartment(): string
- {
- return $this->department;
- }
- /**
- * @param string $department
- */
- public function setDepartment(string $department): void
- {
- $this->department = $department;
- }
- /**
- * @return float
- */
- public function getSalary(): float
- {
- return $this->salary;
- }
- /**
- * @param float $salary
- */
- public function setSalary(float $salary): void
- {
- $this->salary = $salary;
- }
- public function __toString()
- {
- return "{$this->companyName} {$this->department} " . number_format($this->salary, 2);
- }
- }
- class Pokemon
- {
- /**
- * @var string
- */
- private $pokemonName;
- /**
- * @var string
- */
- private $pokemonType;
- public function __construct(string $pokemonName, string $pokemonType)
- {
- $this->pokemonName = $pokemonName;
- $this->pokemonType = $pokemonType;
- }
- /**
- * @return string
- */
- public function getPokemonName(): string
- {
- return $this->pokemonName;
- }
- /**
- * @param string $pokemonName
- */
- public function setPokemonName(string $pokemonName): void
- {
- $this->pokemonName = $pokemonName;
- }
- /**
- * @return string
- */
- public function getPokemonType(): string
- {
- return $this->pokemonType;
- }
- /**
- * @param string $pokemonType
- */
- public function setPokemonType(string $pokemonType): void
- {
- $this->pokemonType = $pokemonType;
- }
- public function __toString()
- {
- return "{$this->pokemonName} {$this->pokemonType}";
- }
- }
- class Parents
- {
- private $parentName;
- private $parentBirthday;
- public function __construct(string $parentName, string $parentBirthday)
- {
- $this->parentName = $parentName;
- $this->parentBirthday = $parentBirthday;
- }
- /**
- * @return string
- */
- public function getParentName(): string
- {
- return $this->parentName;
- }
- /**
- * @return string
- */
- public function getParentBirthday(): string
- {
- return $this->parentBirthday;
- }
- /**
- * @param string $name
- */
- public function setParentName(string $name): void
- {
- $this->parentName = $name;
- }
- /**
- * @param string $birthday
- */
- public function setParentBirthday(string $birthday): void
- {
- $this->parentBirthday = $birthday;
- }
- public function __toString()
- {
- return "{$this->parentName} {$this->parentBirthday}";
- }
- }
- class Children
- {
- /**
- * @var string
- */
- private $childName;
- /**
- * @var string
- */
- private $childBirthday;
- /**
- * Children constructor.
- * @param string $childName
- * @param string $childBirthday
- */
- public function __construct(string $childName, string $childBirthday)
- {
- $this->childName = $childName;
- $this->childBirthday = $childBirthday;
- }
- /**
- * @return string
- */
- public function getChildName(): string
- {
- return $this->childName;
- }
- /**
- * @param string $childName
- */
- public function setChildName(string $childName): void
- {
- $this->childName = $childName;
- }
- /**
- * @return string
- */
- public function getChildBirthday(): string
- {
- return $this->childBirthday;
- }
- /**
- * @param string $childBirthday
- */
- public function setChildBirthday(string $childBirthday): void
- {
- $this->childBirthday = $childBirthday;
- }
- public function __toString()
- {
- return "{$this->childName} {$this->childBirthday}";
- }
- }
- class Car
- {
- /**
- * @var string
- */
- private $carModel;
- /**
- * @var int
- */
- private $carSpeed;
- /**
- * Car constructor.
- * @param string $carModel
- * @param int $carSpeed
- */
- public function __construct(string $carModel, int $carSpeed)
- {
- $this->carModel = $carModel;
- $this->carSpeed = $carSpeed;
- }
- /**
- * @return string
- */
- public function getCarModel(): string
- {
- return $this->carModel;
- }
- /**
- * @param string $carModel
- */
- public function setCarModel(string $carModel): void
- {
- $this->carModel = $carModel;
- }
- /**
- * @return int
- */
- public function getCarSpeed(): int
- {
- return $this->carSpeed;
- }
- /**
- * @param int $carSpeed
- */
- public function setCarSpeed(int $carSpeed): void
- {
- $this->carSpeed = $carSpeed;
- }
- public function __toString()
- {
- return "{$this->carModel} {$this->carSpeed}";
- }
- }
- class Person
- {
- /**
- * @var string
- */
- private $name;
- /**
- * @var Company
- */
- private $company;
- /**
- * @var Pokemon[]
- */
- private $pokemon;
- /**
- * @var Parents[]
- */
- private $parents;
- /**
- * @var Children[]
- */
- private $children;
- /**
- * @var Car
- */
- private $car;
- /**
- * Person constructor.
- * @param string $name
- */
- public function __construct(string $name)
- {
- $this->name = $name;
- $this->pokemon = [];
- $this->parents = [];
- $this->children = [];
- }
- /**
- * @return string
- */
- public function getName(): string
- {
- return $this->name;
- }
- /**
- * @param string $name
- */
- public function setName(string $name): void
- {
- $this->name = $name;
- }
- /**
- * @return Company
- */
- public function getCompany(): Company
- {
- return $this->company;
- }
- /**
- * @param Company $company
- */
- public function setCompany(Company $company): void
- {
- $this->company = $company;
- }
- /**
- * @return Pokemon[]
- */
- public function getPokemon(): array
- {
- return $this->pokemon;
- }
- /**
- * @param Pokemon $pokemon
- */
- public function setPokemon(Pokemon $pokemon): void
- {
- $this->pokemon[] = $pokemon;
- }
- /**
- * @return Parents[]
- */
- public function getParents(): array
- {
- return $this->parents;
- }
- /**
- * @param Parents $parents
- */
- public function setParents(Parents $parents): void
- {
- $this->parents[] = $parents;
- }
- /**
- * @return Children[]
- */
- public function getChildren(): array
- {
- return $this->children;
- }
- /**
- * @param Children $children
- */
- public function setChildren(Children $children): void
- {
- $this->children[] = $children;
- }
- /**
- * @return Car
- */
- public function getCar(): Car
- {
- return $this->car;
- }
- /**
- * @param Car $car
- */
- public function setCar(Car $car): void
- {
- $this->car = $car;
- }
- public function __toString()
- {
- $str = $this->name . PHP_EOL;
- $str .= "Company:\n";
- if($this->company !== null) {
- $str .= $this->company . PHP_EOL;
- }
- $str .= "Car:" . PHP_EOL;
- if($this->car !== null) {
- $str .= $this->car . PHP_EOL;
- }
- $str .= "Pokemon:" . PHP_EOL;
- if(count($this->pokemon) !== 0) {
- foreach ($this->pokemon as $pokemon) {
- $str .= $pokemon . PHP_EOL;
- }
- }
- $str .= "Parents:" . PHP_EOL;
- if(count($this->parents) !== 0) {
- foreach ($this->parents as $parent) {
- $str .= $parent . PHP_EOL;
- }
- }
- $str .= "Children:" . PHP_EOL;
- if(count($this->children) !== 0) {
- foreach ($this->children as $child) {
- $str .= $child . PHP_EOL;
- }
- }
- return $str;
- }
- }
- $input = readline();
- $people = [];
- while($input !== "End") {
- $currentPersonData = explode(" " , $input);
- $name = $currentPersonData[0];
- if (!key_exists($name, $people)) {
- $people[$name] = new Person($name);
- }
- switch ($currentPersonData[1]) {
- case "company":
- $companyName = $currentPersonData[2];
- $department = $currentPersonData[3];
- $salary = $currentPersonData[4];
- $company = new Company($companyName, $department, $salary);
- $people[$name]->setCompany($company);
- break;
- case "pokemon":
- $pokemonName = $currentPersonData[2];
- $pokemonType = $currentPersonData[3];
- $pokemon = new Pokemon($pokemonName, $pokemonType);
- $people[$name]->setPokemon($pokemon);
- break;
- case "parents":
- $parentName = $currentPersonData[2];
- $birthday = $currentPersonData[3];
- $parent = new Parents($parentName, $birthday);
- $people[$name]->setParents($parent);
- break;
- case "children":
- $childName = $currentPersonData[2];
- $birthday = $currentPersonData[3];
- $child = new Children($childName, $birthday);
- $people[$name]->setChildren($child);
- break;
- case "car":
- $carModel = $currentPersonData[2];
- $carSpeed = intval($currentPersonData[3]);
- $car = new Car($carModel, $carSpeed);
- $people[$name]->setCar($car);
- break;
- }
- $input = readline();
- }
- $nameToPrint = readline();
- echo $people[$nameToPrint];
Add Comment
Please, Sign In to add comment