Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Student {
- private $name;
- private $age;
- private $score;
- private $subjects = array (
- 'Arabic' => 0 ,
- 'English' => 0 ,
- 'Math' => 0 ,
- 'Science' => 0
- );
- private $minScore = 150;
- private $maxScore = 300;
- public function __construct($name , $age)
- {
- $this->setName($name);
- $this->setAge($age);
- }
- private function setName($name)
- {
- $name = strtolower($name);
- $name = filter_var($name,FILTER_SANITIZE_STRING);
- $name = ucwords($name);
- $name = substr($name, 0 , 30);
- $this->name = $name;
- }
- public function getName() {
- return $this->name;
- }
- private function setAge($age)
- {
- $age = filter_var($age, FILTER_SANITIZE_NUMBER_INT);
- $age = abs($age);
- if ($age <= 6 || $age >= 18) {
- throw new Exception("Error");
- } else {
- $this->age = $age;
- }
- }
- public function getAge() {
- return $this->age;
- }
- public function getSubject() {
- return $this->subjects;
- }
- public function getMinScore() {
- return $this->minScore;
- }
- public function getMaxScore() {
- return $this->maxScore;
- }
- }
- class Grade1Student extends Student
- {
- public function __construct($name,$age)
- {
- parent::__construct($name,$age);
- $this->minScore=180;
- $this->maxScore=400;
- $this->subjects['Art'] = 0;
- }
- }
- $mohamed = new Grade1Student('Mohamed' , 12);
- print_r($mohamed->getSubject());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement