emotrend

'Google'

Jun 8th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.67 KB | None | 0 0
  1. <?php
  2.  
  3. class Company
  4. {
  5.  
  6.     /**
  7.      * @var string
  8.      */
  9.     private $companyName;
  10.  
  11.  
  12.     /**
  13.      * @var string
  14.      */
  15.     private $department;
  16.  
  17.  
  18.     /**
  19.      * @var float
  20.      */
  21.     private $salary;
  22.  
  23.  
  24.     public function __construct(string $companyName, string $department, float $salary)
  25.     {
  26.         $this->companyName = $companyName;
  27.         $this->department = $department;
  28.         $this->salary = $salary;
  29.     }
  30.  
  31.     /**
  32.      * @return string
  33.      */
  34.     public function getCompanyName(): string
  35.     {
  36.         return $this->companyName;
  37.     }
  38.  
  39.     /**
  40.      * @param string $companyName
  41.      */
  42.     public function setCompanyName(string $companyName): void
  43.     {
  44.         $this->companyName = $companyName;
  45.     }
  46.  
  47.     /**
  48.      * @return string
  49.      */
  50.     public function getDepartment(): string
  51.     {
  52.         return $this->department;
  53.     }
  54.  
  55.     /**
  56.      * @param string $department
  57.      */
  58.     public function setDepartment(string $department): void
  59.     {
  60.         $this->department = $department;
  61.     }
  62.  
  63.     /**
  64.      * @return float
  65.      */
  66.     public function getSalary(): float
  67.     {
  68.         return $this->salary;
  69.     }
  70.  
  71.     /**
  72.      * @param float $salary
  73.      */
  74.     public function setSalary(float $salary): void
  75.     {
  76.         $this->salary = $salary;
  77.     }
  78.  
  79.     public function __toString()
  80.     {
  81.         return "{$this->companyName} {$this->department} " . number_format($this->salary, 2);
  82.     }
  83.  
  84. }
  85.  
  86. class Pokemon
  87. {
  88.  
  89.     /**
  90.      * @var string
  91.      */
  92.     private $pokemonName;
  93.  
  94.  
  95.     /**
  96.      * @var string
  97.      */
  98.     private $pokemonType;
  99.  
  100.     public function __construct(string $pokemonName, string $pokemonType)
  101.     {
  102.         $this->pokemonName = $pokemonName;
  103.         $this->pokemonType = $pokemonType;
  104.     }
  105.  
  106.     /**
  107.      * @return string
  108.      */
  109.     public function getPokemonName(): string
  110.     {
  111.         return $this->pokemonName;
  112.     }
  113.  
  114.     /**
  115.      * @param string $pokemonName
  116.      */
  117.     public function setPokemonName(string $pokemonName): void
  118.     {
  119.         $this->pokemonName = $pokemonName;
  120.     }
  121.  
  122.     /**
  123.      * @return string
  124.      */
  125.     public function getPokemonType(): string
  126.     {
  127.         return $this->pokemonType;
  128.     }
  129.  
  130.     /**
  131.      * @param string $pokemonType
  132.      */
  133.     public function setPokemonType(string $pokemonType): void
  134.     {
  135.         $this->pokemonType = $pokemonType;
  136.     }
  137.  
  138.     public function __toString()
  139.     {
  140.         return "{$this->pokemonName} {$this->pokemonType}";
  141.     }
  142. }
  143.  
  144. class Parents
  145. {
  146.  
  147.     private $parentName;
  148.  
  149.     private $parentBirthday;
  150.  
  151.  
  152.     public function __construct(string $parentName, string $parentBirthday)
  153.     {
  154.         $this->parentName = $parentName;
  155.         $this->parentBirthday = $parentBirthday;
  156.     }
  157.  
  158.     /**
  159.      * @return string
  160.      */
  161.     public function getParentName(): string
  162.     {
  163.         return $this->parentName;
  164.     }
  165.  
  166.     /**
  167.      * @return string
  168.      */
  169.     public function getParentBirthday(): string
  170.     {
  171.         return $this->parentBirthday;
  172.     }
  173.  
  174.     /**
  175.      * @param string $name
  176.      */
  177.     public function setParentName(string $name): void
  178.     {
  179.         $this->parentName = $name;
  180.     }
  181.  
  182.     /**
  183.      * @param string $birthday
  184.      */
  185.     public function setParentBirthday(string $birthday): void
  186.     {
  187.         $this->parentBirthday = $birthday;
  188.     }
  189.  
  190.     public function __toString()
  191.     {
  192.         return "{$this->parentName} {$this->parentBirthday}";
  193.     }
  194. }
  195.  
  196. class Children
  197. {
  198.  
  199.     /**
  200.      * @var string
  201.      */
  202.     private $childName;
  203.  
  204.  
  205.     /**
  206.      * @var string
  207.      */
  208.     private $childBirthday;
  209.  
  210.     /**
  211.      * Children constructor.
  212.      * @param string $childName
  213.      * @param string $childBirthday
  214.      */
  215.     public function __construct(string $childName, string $childBirthday)
  216.     {
  217.         $this->childName = $childName;
  218.         $this->childBirthday = $childBirthday;
  219.     }
  220.  
  221.     /**
  222.      * @return string
  223.      */
  224.     public function getChildName(): string
  225.     {
  226.         return $this->childName;
  227.     }
  228.  
  229.     /**
  230.      * @param string $childName
  231.      */
  232.     public function setChildName(string $childName): void
  233.     {
  234.         $this->childName = $childName;
  235.     }
  236.  
  237.     /**
  238.      * @return string
  239.      */
  240.     public function getChildBirthday(): string
  241.     {
  242.         return $this->childBirthday;
  243.     }
  244.  
  245.     /**
  246.      * @param string $childBirthday
  247.      */
  248.     public function setChildBirthday(string $childBirthday): void
  249.     {
  250.         $this->childBirthday = $childBirthday;
  251.     }
  252.  
  253.     public function __toString()
  254.     {
  255.         return "{$this->childName} {$this->childBirthday}";
  256.     }
  257. }
  258.  
  259. class Car
  260. {
  261.  
  262.     /**
  263.      * @var string
  264.      */
  265.     private $carModel;
  266.  
  267.     /**
  268.      * @var int
  269.      */
  270.     private $carSpeed;
  271.  
  272.     /**
  273.      * Car constructor.
  274.      * @param string $carModel
  275.      * @param int $carSpeed
  276.      */
  277.     public function __construct(string $carModel, int $carSpeed)
  278.     {
  279.         $this->carModel = $carModel;
  280.         $this->carSpeed = $carSpeed;
  281.     }
  282.  
  283.     /**
  284.      * @return string
  285.      */
  286.     public function getCarModel(): string
  287.     {
  288.         return $this->carModel;
  289.     }
  290.  
  291.     /**
  292.      * @param string $carModel
  293.      */
  294.     public function setCarModel(string $carModel): void
  295.     {
  296.         $this->carModel = $carModel;
  297.     }
  298.  
  299.     /**
  300.      * @return int
  301.      */
  302.     public function getCarSpeed(): int
  303.     {
  304.         return $this->carSpeed;
  305.     }
  306.  
  307.     /**
  308.      * @param int $carSpeed
  309.      */
  310.     public function setCarSpeed(int $carSpeed): void
  311.     {
  312.         $this->carSpeed = $carSpeed;
  313.     }
  314.  
  315.     public function __toString()
  316.     {
  317.         return "{$this->carModel} {$this->carSpeed}";
  318.     }
  319. }
  320.  
  321. class Person
  322. {
  323.  
  324.     /**
  325.      * @var string
  326.      */
  327.     private $name;
  328.  
  329.  
  330.     /**
  331.      * @var Company
  332.      */
  333.     private $company;
  334.  
  335.     /**
  336.      * @var Pokemon[]
  337.      */
  338.     private $pokemon;
  339.  
  340.     /**
  341.      * @var Parents[]
  342.      */
  343.     private $parents;
  344.  
  345.  
  346.     /**
  347.      * @var Children[]
  348.      */
  349.     private $children;
  350.  
  351.  
  352.     /**
  353.      * @var Car
  354.      */
  355.     private $car;
  356.  
  357.     /**
  358.      * Person constructor.
  359.      * @param string $name
  360.      */
  361.     public function __construct(string $name)
  362.     {
  363.         $this->name = $name;
  364.         $this->pokemon = [];
  365.         $this->parents = [];
  366.         $this->children = [];
  367.     }
  368.  
  369.     /**
  370.      * @return string
  371.      */
  372.     public function getName(): string
  373.     {
  374.         return $this->name;
  375.     }
  376.  
  377.     /**
  378.      * @param string $name
  379.      */
  380.     public function setName(string $name): void
  381.     {
  382.         $this->name = $name;
  383.     }
  384.  
  385.     /**
  386.      * @return Company
  387.      */
  388.     public function getCompany(): Company
  389.     {
  390.         return $this->company;
  391.     }
  392.  
  393.     /**
  394.      * @param Company $company
  395.      */
  396.     public function setCompany(Company $company): void
  397.     {
  398.         $this->company = $company;
  399.     }
  400.  
  401.     /**
  402.      * @return Pokemon[]
  403.      */
  404.     public function getPokemon(): array
  405.     {
  406.         return $this->pokemon;
  407.     }
  408.  
  409.     /**
  410.      * @param Pokemon $pokemon
  411.      */
  412.     public function setPokemon(Pokemon $pokemon): void
  413.     {
  414.         $this->pokemon[] = $pokemon;
  415.     }
  416.  
  417.     /**
  418.      * @return Parents[]
  419.      */
  420.     public function getParents(): array
  421.     {
  422.         return $this->parents;
  423.     }
  424.  
  425.     /**
  426.      * @param Parents $parents
  427.      */
  428.     public function setParents(Parents $parents): void
  429.     {
  430.         $this->parents[] = $parents;
  431.     }
  432.  
  433.     /**
  434.      * @return Children[]
  435.      */
  436.     public function getChildren(): array
  437.     {
  438.         return $this->children;
  439.     }
  440.  
  441.     /**
  442.      * @param Children $children
  443.      */
  444.     public function setChildren(Children $children): void
  445.     {
  446.         $this->children[] = $children;
  447.     }
  448.  
  449.     /**
  450.      * @return Car
  451.      */
  452.     public function getCar(): Car
  453.     {
  454.         return $this->car;
  455.     }
  456.  
  457.     /**
  458.      * @param Car $car
  459.      */
  460.     public function setCar(Car $car): void
  461.     {
  462.         $this->car = $car;
  463.     }
  464.  
  465.  
  466.     public function __toString()
  467.     {
  468.  
  469.         $str = $this->name . PHP_EOL;
  470.  
  471.         $str .= "Company:\n";
  472.  
  473.         if($this->company !== null) {
  474.             $str .= $this->company . PHP_EOL;
  475.         }
  476.  
  477.         $str .= "Car:" . PHP_EOL;
  478.  
  479.         if($this->car !== null) {
  480.             $str .= $this->car . PHP_EOL;
  481.         }
  482.  
  483.         $str .= "Pokemon:" . PHP_EOL;
  484.  
  485.         if(count($this->pokemon) !== 0) {
  486.             foreach ($this->pokemon as $pokemon) {
  487.                 $str .= $pokemon . PHP_EOL;
  488.             }
  489.         }
  490.  
  491.         $str .= "Parents:" . PHP_EOL;
  492.  
  493.         if(count($this->parents) !== 0) {
  494.             foreach ($this->parents as $parent) {
  495.                 $str .= $parent . PHP_EOL;
  496.             }
  497.         }
  498.  
  499.         $str .= "Children:" . PHP_EOL;
  500.  
  501.         if(count($this->children) !== 0) {
  502.             foreach ($this->children as $child) {
  503.                 $str .= $child . PHP_EOL;
  504.             }
  505.         }
  506.  
  507.  
  508.         return $str;
  509.     }
  510. }
  511.  
  512. $input = readline();
  513. $people = [];
  514.  
  515. while($input !== "End") {
  516.  
  517.     $currentPersonData = explode(" " , $input);
  518.  
  519.     $name = $currentPersonData[0];
  520.  
  521.     if (!key_exists($name, $people)) {
  522.         $people[$name] = new Person($name);
  523.     }
  524.  
  525.     switch ($currentPersonData[1]) {
  526.         case "company":
  527.             $companyName = $currentPersonData[2];
  528.             $department = $currentPersonData[3];
  529.             $salary = $currentPersonData[4];
  530.             $company = new Company($companyName, $department, $salary);
  531.             $people[$name]->setCompany($company);
  532.             break;
  533.         case "pokemon":
  534.             $pokemonName = $currentPersonData[2];
  535.             $pokemonType = $currentPersonData[3];
  536.             $pokemon = new Pokemon($pokemonName, $pokemonType);
  537.             $people[$name]->setPokemon($pokemon);
  538.             break;
  539.         case "parents":
  540.             $parentName = $currentPersonData[2];
  541.             $birthday = $currentPersonData[3];
  542.             $parent = new Parents($parentName, $birthday);
  543.             $people[$name]->setParents($parent);
  544.             break;
  545.         case "children":
  546.             $childName = $currentPersonData[2];
  547.             $birthday = $currentPersonData[3];
  548.             $child = new Children($childName, $birthday);
  549.             $people[$name]->setChildren($child);
  550.             break;
  551.         case "car":
  552.             $carModel = $currentPersonData[2];
  553.             $carSpeed = intval($currentPersonData[3]);
  554.             $car = new Car($carModel, $carSpeed);
  555.             $people[$name]->setCar($car);
  556.             break;
  557.     }
  558.  
  559.     $input = readline();
  560. }
  561.  
  562. $nameToPrint = readline();
  563.  
  564. echo $people[$nameToPrint];
Add Comment
Please, Sign In to add comment