Advertisement
ShadowEmbrace

Students

Nov 19th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2.  
  3. class Student
  4. {
  5.     private $firstName;
  6.     private $lastName;
  7.     private $age;
  8.     private $hometown;
  9.  
  10.     public function __construct($firstName, $lastName, $age, $hometown)
  11.     {
  12.         $this->firstName = $firstName;
  13.         $this->lastName = $lastName;
  14.         $this->age = $age;
  15.         $this->hometown = $hometown;
  16.     }
  17.  
  18.     /**
  19.      * @return mixed
  20.      */
  21.     public function getFirstName()
  22.     {
  23.         return $this->firstName;
  24.     }
  25.  
  26.     /**
  27.      * @param mixed $firstName
  28.      */
  29.     private function setFirstName($firstName): void
  30.     {
  31.         $this->firstName = $firstName;
  32.     }
  33.  
  34.     /**
  35.      * @return mixed
  36.      */
  37.     public function getLastName()
  38.     {
  39.         return $this->lastName;
  40.     }
  41.  
  42.     /**
  43.      * @param mixed $lastName
  44.      */
  45.     private function setLastName($lastName): void
  46.     {
  47.         $this->lastName = $lastName;
  48.     }
  49.  
  50.     /**
  51.      * @return mixed
  52.      */
  53.     public function getAge()
  54.     {
  55.         return $this->age;
  56.     }
  57.  
  58.     /**
  59.      * @param mixed $age
  60.      */
  61.     private function setAge($age): void
  62.     {
  63.         $this->age = $age;
  64.     }
  65.  
  66.     /**
  67.      * @return mixed
  68.      */
  69.     public function getHometown()
  70.     {
  71.         return $this->hometown;
  72.     }
  73.  
  74.     /**
  75.      * @param mixed $hometown
  76.      */
  77.     private function setHometown($hometown): void
  78.     {
  79.         $this->hometown = $hometown;
  80.     }
  81. }
  82.  
  83. $students = [];
  84. $input = explode(' ', readline());
  85.  
  86. while ($input[0] !== 'end') {
  87.     list($firstName, $lastName, $age, $hometown) = $input;
  88.     $student = new Student($firstName, $lastName, $age, $hometown);
  89.     $students[] = $student;
  90.     $input = explode(' ', readline());
  91. }
  92.  
  93. $town = readline();
  94.  
  95. foreach ($students as $studentInfo) {
  96.     if ($studentInfo->getHomeTown() === $town) {
  97.         echo $studentInfo->getFirstName() . ' ' . $studentInfo->getLastName() . ' is ' .
  98.             $studentInfo->getAge() . ' years old.' . PHP_EOL;
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement