fork download
  1. <?php
  2.  
  3. abstract class Employee
  4. {
  5. protected $boss;
  6. protected $rang;
  7. protected $salary;
  8. protected $coffeeValue;
  9. protected $paper;
  10.  
  11. function __construct($boss, $rang)
  12. {
  13. $this->boss = $boss;
  14. $this->rang = $rang;
  15. }
  16.  
  17. static function recruit ($boss, $rang, $class) {
  18. return new $class($boss, $rang);
  19. }
  20.  
  21. public function getSalary()
  22. {
  23. $salary;
  24.  
  25. switch ($this->rang) {
  26. case 2:
  27. $salary = $this->salary * 1.25;
  28. break;
  29. case 3:
  30. $salary = $this->salary * 1.5;
  31. break;
  32. default:
  33. $salary = $this->salary;
  34. break;
  35. }
  36.  
  37. if ($this->boss == true) {
  38. $salary *= 1.3;
  39. }
  40.  
  41. return $salary;
  42. }
  43.  
  44. public function getCoffee() {
  45. if ($this->boss) {
  46. return $this->coffeeValue*2;
  47. }
  48. return $this->coffeeValue;
  49. }
  50.  
  51. public function getPaper() {
  52. if ($this->boss) {
  53. return 0;
  54. }
  55. return $this->paper;
  56. }
  57. }
  58.  
  59. class Manager extends Employee
  60. {
  61. function __construct($boss, $rang)
  62. {
  63. parent::__construct($boss, $rang);
  64. $this->salary = 500;
  65. $this->coffeeValue = 20;
  66. $this->paper = 200;
  67. }
  68. }
  69.  
  70. class Marketer extends Employee
  71. {
  72. function __construct($boss, $rang)
  73. {
  74. parent::__construct($boss, $rang);
  75. $this->salary = 400;
  76. $this->coffeeValue = 15;
  77. $this->paper = 150;
  78. }
  79. }
  80.  
  81. class Engineer extends Employee
  82. {
  83. function __construct($boss, $rang)
  84. {
  85. parent::__construct($boss, $rang);
  86. $this->salary = 200;
  87. $this->coffeeValue = 5;
  88. $this->paper = 50;
  89. }
  90. }
  91.  
  92. class Analyst extends Employee
  93. {
  94. function __construct($boss, $rang)
  95. {
  96. parent::__construct($boss, $rang);
  97. $this->salary = 800;
  98. $this->coffeeValue = 50;
  99. $this->paper = 5;
  100. }
  101. }
  102.  
  103.  
  104. class Departament
  105. {
  106. private $employees = array();
  107. private $nameOfDepartament;
  108.  
  109. public function __construct ($name) {
  110. $this->nameOfDepartament = $name;
  111. }
  112.  
  113. private function newEmployee($number, $class, $rang, $boss = false)
  114. {
  115. for ($i=0; $i < $number; $i++) {
  116. $this->employees[] = Employee::recruit($boss, $rang, $class);
  117. }
  118. }
  119.  
  120. public function addEmployees($number, $class, $rang)
  121. {
  122. $this->newEmployee($number, $class, $rang);
  123. }
  124.  
  125. public function addDirector($class, $rang)
  126. {
  127. $this->newEmployee(1, $class, $rang, $boss = true);
  128. }
  129.  
  130. public function getEmployees()
  131. {
  132. return $this->employees;
  133. }
  134.  
  135. public function calculateCostForASalary()
  136. {
  137. $sumOfSalary = 0;
  138. foreach ($this->employees as $employee) {
  139. $sumOfSalary += $employee->getSalary();
  140. }
  141. return $sumOfSalary;
  142. }
  143.  
  144. public function calculateAmountOfCoffe()
  145. {
  146. $amountOfCoffe = 0;
  147. foreach ($this->employees as $employee) {
  148. $amountOfCoffe += $employee->getCoffee();
  149. }
  150. return $amountOfCoffe;
  151. }
  152.  
  153. public function calculateAmountOfPaper()
  154. {
  155. $amountOfPaper = 0;
  156. foreach ($this->employees as $employee) {
  157. $amountOfPaper += $employee->getPaper();
  158. }
  159. return $amountOfPaper;
  160. }
  161.  
  162. public function getNameOfDepartament() {
  163. return $this->nameOfDepartament;
  164. }
  165.  
  166. }
  167.  
  168.  
  169. class Company
  170. {
  171. private $departaments = array();
  172.  
  173. public function __construct()
  174. {
  175. $departament = new Departament("Отдел закупок");
  176. $departament->addEmployees(9, "Manager", 1);
  177. $departament->addEmployees(3, "Manager", 2);
  178. $departament->addEmployees(2, "Manager", 1);
  179. $departament->addEmployees(2, "Marketer", 1);
  180. $departament->addDirector("Manager", 2);
  181.  
  182. $this->departaments[] = $departament;
  183.  
  184. $departament = new Departament("Отдел продаж");
  185. $departament->addEmployees(12, "Manager", 1);
  186. $departament->addEmployees(6, "Marketer", 1);
  187. $departament->addEmployees(3, "Analyst", 1);
  188. $departament->addEmployees(2, "Analyst", 1);
  189. $departament->addDirector("Marketer", 2);
  190.  
  191. $this->departaments[] = $departament;
  192.  
  193. $departament = new Departament("Отдел рекламы");
  194. $departament->addEmployees(15, "Manager", 1);
  195. $departament->addEmployees(10, "Marketer", 2);
  196. $departament->addEmployees(8, "Manager", 1);
  197. $departament->addEmployees(2, "Engineer", 1);
  198. $departament->addDirector("Marketer", 3);
  199.  
  200. $this->departaments[] = $departament;
  201.  
  202. $departament = new Departament("Отдел логистики");
  203. $departament->addEmployees(13, "Manager", 1);
  204. $departament->addEmployees(5, "Manager", 2);
  205. $departament->addEmployees(5, "Marketer", 1);
  206. $departament->addDirector("Manager", 1);
  207.  
  208. $this->departaments[] = $departament;
  209. }
  210.  
  211. public function showInformation()
  212. {
  213. $sumOfSalary;
  214. $sumOfCoffee;
  215. $sumOfPaper;
  216. $sumOfEmployees;
  217.  
  218. foreach ($this->departaments as $departament) {
  219. echo ( "Название: ".$departament->getNameOfDepartament()."\n" );
  220. echo ( "Зарплата всего: ".$departament->calculateCostForASalary()."\n" );
  221. $sumOfSalary += $departament->calculateCostForASalary();
  222. echo ( "Кофе всего: ".$departament->calculateAmountOfCoffe()."\n" );
  223. $sumOfCoffee += $departament->calculateAmountOfCoffe();
  224. echo ( "Страниц всего: ".$departament->calculateAmountOfPaper()."\n" );
  225. $sumOfPaper += $departament->calculateAmountOfPaper();
  226. echo ( "Работников всего: ".count( $departament->getEmployees() ) );
  227. $sumOfEmployees += count( $departament->getEmployees() );
  228. echo ( "\n\n" );
  229. }
  230.  
  231. echo ( "Всего сотрудников: ".$sumOfEmployees."\n" );
  232. echo ( "Всего затрачено на зарплату: ".$sumOfSalary."\n" );
  233. echo ( "Всего выпито кофе: ".$sumOfCoffee."\n" );
  234. echo ( "Всего страниц: ".$sumOfPaper."\n" );
  235.  
  236. echo ( "\n\n" );
  237.  
  238. echo ( "В среднем сотрудников: ".$sumOfEmployees/count( $this->departaments )."\n" );
  239. echo ( "В среднем затрачено на зарплату: ".$sumOfSalary/count( $this->departaments )."\n" );
  240. echo ( "В среднем выпито кофе: ".$sumOfCoffee/count( $this->departaments )."\n" );
  241. echo ( "В среднем страниц: ".$sumOfPaper/count( $this->departaments )."\n" );
  242.  
  243. }
  244.  
  245. }
  246.  
  247. $company1 = new Company();
  248. $company1->showInformation();
Success #stdin #stdout #stderr 0.01s 52488KB
stdin
Standard input is empty
stdout
Название: Отдел закупок
Зарплата всего: 8987.5
Кофе всего: 350
Страниц всего: 3100
Работников всего: 17

Название: Отдел продаж
Зарплата всего: 13050
Кофе всего: 610
Страниц всего: 3325
Работников всего: 24

Название: Отдел рекламы
Зарплата всего: 17680
Кофе всего: 650
Страниц всего: 6200
Работников всего: 36

Название: Отдел логистики
Зарплата всего: 12275
Кофе всего: 475
Страниц всего: 4350
Работников всего: 24

Всего сотрудников: 101
Всего затрачено на зарплату: 51992.5
Всего выпито кофе: 2085
Всего страниц: 16975


В среднем сотрудников: 25.25
В среднем затрачено на зарплату: 12998.125
В среднем выпито кофе: 521.25
В среднем страниц: 4243.75
stderr
PHP Notice:  Undefined variable: sumOfSalary in /home/kGVikj/prog.php on line 221
PHP Notice:  Undefined variable: sumOfCoffee in /home/kGVikj/prog.php on line 223
PHP Notice:  Undefined variable: sumOfPaper in /home/kGVikj/prog.php on line 225
PHP Notice:  Undefined variable: sumOfEmployees in /home/kGVikj/prog.php on line 227