fork(3) download
  1. <?php
  2.  
  3. abstract class Employee
  4. {
  5.  
  6. public $salary;
  7. public $pages;
  8. public $cofee;
  9. public $name;
  10.  
  11.  
  12. function __construct($rank)
  13. {
  14.  
  15.  
  16. $this->rank = $rank;
  17. }
  18.  
  19. function getSalary()
  20. {
  21. $multiply = 1;
  22. switch ($this->rank) {
  23. case 2:
  24. $multiply = 1.25;
  25. break;
  26. case 3:
  27. $multiply = 1.50;
  28. break;
  29. }
  30. return $this->salary * $multiply;
  31.  
  32. }
  33.  
  34.  
  35.  
  36. }
  37.  
  38. class Manager extends Employee
  39. {
  40. public $name = "Менеджер";
  41. public $salary = 500;
  42. public $cofee = 20;
  43. public $pages = 200;
  44. }
  45.  
  46. class Market extends Employee
  47. {
  48. public $name = "Маркетолог";
  49. public $salary = 400;
  50. public $cofee = 15;
  51. public $pages = 150;
  52. }
  53.  
  54. class Engineer extends Employee
  55. {
  56. public $name = "Инженер";
  57. public $salary = 200;
  58. public $cofee = 5;
  59. public $pages = 50;
  60. }
  61.  
  62. class Analyst extends Employee
  63. {
  64. public $name = "Аналитик";
  65. public $salary = 800;
  66. public $cofee = 50;
  67. public $pages = 5;
  68. }
  69.  
  70.  
  71. class Department
  72. {
  73. function workers($data)
  74. {
  75. return count($data) - 1;
  76. }
  77. function cofee($data)
  78. {
  79. $cofee = 0;
  80. foreach ($data as $key => $worker) {
  81. if ($key === 'name') {
  82. continue;
  83. }
  84. $cofee += $worker->cofee;
  85. }
  86. return $cofee;
  87. }
  88. function costs($data)
  89. {
  90. $costs = 0;
  91. foreach ($data as $key => $worker) {
  92. if ($key === 'name') {
  93. continue;
  94. }
  95. $costs += $worker->getSalary();
  96. }
  97. return $costs;
  98. }
  99. function pages($data)
  100. {
  101. $pages = 0;
  102. foreach ($data as $key => $worker) {
  103. if ($key === 'name') {
  104. continue;
  105. }
  106. $pages += $worker->pages;
  107. }
  108. return $pages;
  109. }
  110.  
  111. function __construct($name)
  112. {
  113. $this->name = $name;
  114. return $this->name;
  115. }
  116. }
  117. $department1 = array(
  118. 'name' => 'продаж'
  119. );
  120. for ($i = 0; $i < 9; $i++) {
  121. $department1[] = new Manager(1);
  122. }
  123.  
  124. for ($i = 0; $i < 3; $i++) {
  125. $department1[] = new Manager(2);
  126. }
  127.  
  128. for ($i = 0; $i < 2; $i++) {
  129. $department1[] = new Manager(3);
  130. }
  131.  
  132. for ($i = 0; $i < 2; $i++) {
  133. $department1[] = new Market(1);
  134. }
  135.  
  136.  
  137.  
  138. function createDepartment($data)
  139. {
  140. $department = new Department($data['name']);
  141.  
  142.  
  143. echo "Департамент " . $department->name;
  144. echo " \n Работников {$department->workers($data)}";
  145. echo " \n Расходы {$department->costs($data)}";
  146. echo " \n Кофе {$department->cofee($data)}";
  147. echo " \n Страницы {$department->pages($data)}";
  148.  
  149. }
  150.  
  151. createDepartment($department1);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Департамент продаж 
 Работников 16 
 Расходы 8675 
 Кофе 310 
 Страницы 3100