fork download
  1. <?php
  2.  
  3. abstract class Worker
  4. {
  5. private $department;
  6. private $rank;
  7. private $isChief;
  8. private $baseSalary;
  9. private $coffeeConsumptionRate;
  10. private $productionPerMount;
  11. private $productionType;
  12. public function __construct( $department, $rank, $chief )
  13. {
  14. $this->department = $department;
  15. $this->rank = $rank;
  16. $this->isChief = $chief;
  17. }
  18. public function getCoffeeConsumption()
  19. {
  20. if ( $this->isChief )
  21. {
  22. $coffee = $coffeeConsumptionRate*1.5;
  23. }
  24. else
  25. {
  26. $coffee = $coffeeConsumptionRate;
  27. }
  28. return $coffee;
  29. }
  30.  
  31. public function getSalary()
  32. {
  33. switch( $this->rank )
  34. {
  35. case 1:
  36. $salary = $baseSalary;
  37. break;
  38. case 2:
  39. $salary = $baseSalary*1.25;
  40. break;
  41. case 3:
  42. $salary = $baseSalary*1.5;
  43. break;
  44. }
  45. if( $isChief )
  46. {
  47. $salary*= 1.5;
  48. }
  49. return $salary;
  50. }
  51.  
  52. abstract function getInfos();
  53. }
  54.  
  55. class Manager extends Worker
  56. {
  57. private $coffeeConsumptionRate = 20;
  58. private $baseSalary = 500;
  59. private $productionPerMount = 200;
  60. private $productionType = "страница отчёта";
  61.  
  62. public function getInfos()
  63. {
  64. echo "Это менеджер ";
  65. echo $this->rank;
  66. echo " уровня из департамента ";
  67. echo $this->department;
  68. if ($this->isChief)
  69. {
  70. echo "\nОн начальник этого департамента.";
  71. }
  72. echo "\nПолучает ";
  73. echo $this->getSalary();
  74. echo " единиц валюты в месяц\n";
  75. echo "Выпивает ";
  76. echo $this->getCoffeeConsumption();
  77. echo " литров кофе в месяц\n";
  78. }
  79. }
  80.  
  81. $a = new Manager( "торговый", 2, true );
  82. $a->getInfos();
Success #stdin #stdout #stderr 0.03s 52480KB
stdin
Standard input is empty
stdout
Это менеджер  уровня из департамента 
Получает 0 единиц валюты в месяц
Выпивает 0 литров кофе в месяц
stderr
PHP Notice:  Undefined property: Manager::$rank in /home/7kZUHc/prog.php on line 65
PHP Notice:  Undefined property: Manager::$department in /home/7kZUHc/prog.php on line 67
PHP Notice:  Undefined property: Manager::$isChief in /home/7kZUHc/prog.php on line 68
PHP Notice:  Undefined variable: baseSalary in /home/7kZUHc/prog.php on line 39
PHP Notice:  Undefined variable: isChief in /home/7kZUHc/prog.php on line 46
PHP Notice:  Undefined variable: coffeeConsumptionRate in /home/7kZUHc/prog.php on line 22