Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Student
- {
- private $firstName;
- private $lastName;
- private $age;
- private $hometown;
- public function __construct($firstName, $lastName, $age, $hometown)
- {
- $this->firstName = $firstName;
- $this->lastName = $lastName;
- $this->age = $age;
- $this->hometown = $hometown;
- }
- /**
- * @return mixed
- */
- public function getFirstName()
- {
- return $this->firstName;
- }
- /**
- * @param mixed $firstName
- */
- private function setFirstName($firstName): void
- {
- $this->firstName = $firstName;
- }
- /**
- * @return mixed
- */
- public function getLastName()
- {
- return $this->lastName;
- }
- /**
- * @param mixed $lastName
- */
- private function setLastName($lastName): void
- {
- $this->lastName = $lastName;
- }
- /**
- * @return mixed
- */
- public function getAge()
- {
- return $this->age;
- }
- /**
- * @param mixed $age
- */
- private function setAge($age): void
- {
- $this->age = $age;
- }
- /**
- * @return mixed
- */
- public function getHometown()
- {
- return $this->hometown;
- }
- /**
- * @param mixed $hometown
- */
- private function setHometown($hometown): void
- {
- $this->hometown = $hometown;
- }
- }
- $students = [];
- $input = explode(' ', readline());
- while ($input[0] !== 'end') {
- list($firstName, $lastName, $age, $hometown) = $input;
- $student = new Student($firstName, $lastName, $age, $hometown);
- $students[] = $student;
- $input = explode(' ', readline());
- }
- $town = readline();
- foreach ($students as $studentInfo) {
- if ($studentInfo->getHomeTown() === $town) {
- echo $studentInfo->getFirstName() . ' ' . $studentInfo->getLastName() . ' is ' .
- $studentInfo->getAge() . ' years old.' . PHP_EOL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement