fork download
  1. <?php
  2. class WORKER
  3. {
  4. public $rank;
  5. public $boss;
  6. function __construct($rank, $boss)
  7. {
  8. $this->rank = $rank;
  9. $this->boss = $boss;
  10. }
  11. function money()
  12. {
  13. if ($this->rank == 1) {
  14. $money = $this->money;
  15. }
  16. if ($this->rank == 2) {
  17. $money = $this->money * 1.25;
  18. }
  19. if ($this->rank == 3) {
  20. $money = $this->money * 1.5;
  21. }
  22. if ($this->boss) {
  23. return $money * 1.5;
  24. } else
  25. return $money;
  26. }
  27. function cofe()
  28. {
  29. if ($this->boss) {
  30. $cofe = 2 * $this->cofe;
  31. return $cofe;
  32. } else {
  33. return $this->cofe;
  34. }
  35. }
  36. function page()
  37. {
  38. if ($this->boss) {
  39. $page = 0;
  40. return $page;
  41. } else {
  42. return $this->page;
  43. }
  44. }
  45. }
  46. class MANAGER extends WORKER
  47. {
  48. public $money = 400;
  49. public $cofe = 15;
  50. public $page = 150;
  51. }
  52. class ENGINEER extends WORKER
  53. {
  54. public $money = 200;
  55. public $cofe = 10;
  56. public $page = 100;
  57. }
  58. class Department
  59. {
  60. public $name;
  61. public $workers = array();
  62. function __construct($name, $workers)
  63. {
  64. $this->name = $name;
  65. $this->workers = $workers;
  66. }
  67. function sumMoney()
  68. {
  69. $sumMoney="";
  70. foreach ($this->workers as $worker) {
  71. $sumMoney = $sumMoney + $worker->money();
  72. }
  73. return $sumMoney;
  74. }
  75. function sumCofe()
  76. {
  77. $sumCofe="";
  78. foreach ($this->workers as $worker) {
  79. $sumCofe = $sumCofe + $worker->cofe();
  80. }
  81. return $sumCofe;
  82. }
  83. function sumPage()
  84. {
  85. $sumPage="";
  86. foreach ($this->workers as $worker) {
  87. $sumPage = $sumPage + $worker->page();
  88. }
  89. return $sumPage;
  90. }
  91. }
  92. $wm1 = new MANAGER(2, true);
  93. $wm2 = new MANAGER(1, false);
  94. $we1 = new ENGINEER(2, false);
  95.  
  96. $purchase = array(
  97. $wm1,
  98. $wm2,
  99. $we1
  100. );
  101. $purDep = new Department('Департамент закупок', $purchase);
  102.  
  103. echo $purDep->name;
  104. echo "\n Сумма по зарплатам - " . $purDep->sumMoney();
  105. echo "\n Количество выпитого кофе - " . $purDep->sumCofe();
  106. echo "\n Количество страниц - " . $purDep->sumPage();
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
Департамент закупок
 Сумма по зарплатам - 1400
 Количество выпитого кофе - 55
 Количество страниц - 250