Решение 2 задачи

ООП задачи.


class Worker {
  private $name;
  private $age;
  private $salary;

  public function setName ($name) {
    $this-> name = $name ;
  }
  public function getName () {
   return  $this-> name;
  }
  public function setAge ($age) {
     $this -> checkAge ($age);
  }
  public function getAge () {
    return  $this-> age;
  }
  public function setSalary ($salary) {
    $this-> salary = $salary;
  }
  public function getSalary () {
      return  $this-> salary; 
  }
  private  function  checkAge ($age) {
    if (($age>0) and ($age<100)) {
     $this-> age =$age;
    }
  }

}
 
$human = new Worker;
$human -> setName ('Ivan');
$human -> setAge (27);
$human -> setSalary (1000);
echo "Imya: ".$human -> getName ()."<BR>";
echo "Age: ".$human -> getAge ()."<BR>";
echo "Salary: ".$human -> getSalary ()."<BR>";
$human1 = new Worker;
$human1 -> setName ('Vasya');
$human1 -> setAge (26);
$human1 -> setSalary (2000);
echo "Imya: ".$human1 -> getName ()."<BR>";
echo "Age: ".$human1 -> getAge ()."<BR>";
echo "Salary: ".$human1 -> getSalary ()."<BR>";
$sum = $human -> getAge ()+$human1->getAge ();
echo "Summa Age: ".$sum;