fork(1) 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($quantity, $rank)
  13. {
  14.  
  15. $this->quantity = $quantity;
  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. $getSalary = $this->salary * $multiply * $this->quantity;
  31. return $getSalary;
  32. }
  33.  
  34. function getCofee()
  35. {
  36. $getCofee = $this->quantity * $this->cofee;
  37. return $getCofee;
  38. }
  39.  
  40. function getPages()
  41. {
  42. $getPages = $this->quantity * $this->pages;
  43. return $getPages;
  44. }
  45.  
  46. }
  47.  
  48. class Manager extends Employee
  49. {
  50. public $name = "Менеджер";
  51. public $salary = 500;
  52. public $cofee = 20;
  53. public $pages = 200;
  54. }
  55.  
  56. class Market extends Employee
  57. {
  58. public $name = "Маркетолог";
  59. public $salary = 400;
  60. public $cofee = 15;
  61. public $pages = 150;
  62. }
  63.  
  64. class Engineer extends Employee
  65. {
  66. public $name = "Инженер";
  67. public $salary = 200;
  68. public $cofee = 5;
  69. public $pages = 50;
  70. }
  71.  
  72. class Analyst extends Employee
  73. {
  74. public $name = "Аналитик";
  75. public $salary = 800;
  76. public $cofee = 50;
  77. public $pages = 5;
  78. }
  79.  
  80.  
  81. class Department
  82. {
  83. public $workers;
  84. public $costs;
  85. public $totalCofee;
  86. public $totalPages;
  87.  
  88. function __construct($name)
  89. {
  90. $this->name = $name;
  91. return $this->name;
  92. }
  93. }
  94.  
  95. $department1 = array(
  96. new Manager(9, 1),
  97. new Manager(3, 2),
  98. new Manager(2, 3),
  99. new Market(2, 1),
  100. 'name' => 'закупок'
  101. );
  102.  
  103.  
  104. function createDepartment($data)
  105. {
  106. $department = new Department($data['name']);
  107. foreach ($data as $key => $workers) {
  108. if (!is_numeric($key)) {
  109. continue;
  110. }
  111. $department->workers = $department->workers + $data[$key]->quantity;
  112. $department->costs = $department->costs + $data[$key]->getSalary();
  113. $department->totalCofee = $department->totalCofee + $data[$key]->getCofee();
  114. $department->totalPages = $department->totalPages + $data[$key]->getPages();
  115. }
  116. echo "Департамент " . $department->name;
  117. echo " \n Работников {$department->workers}";
  118. echo " \n Расходы {$department->costs}";
  119. echo "\n Кофе {$department->totalCofee}";
  120. echo " \n Страниц $department->totalPages";
  121. }
  122.  
  123. createDepartment($department1);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Департамент закупок 
 Работников 16 
 Расходы 8675
 Кофе  310 
 Страниц 3100