fork download
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Саша Поляны
  5.  * Date: 14.04.2016
  6.  * Time: 20:25
  7.  */
  8.  
  9. class Employee {
  10. protected $rank = 1;
  11. protected $coffee = 0;
  12. protected $pages = 0;
  13. protected $basicSalary = 0;
  14. protected $boss = false;
  15.  
  16. public function getSalary() {
  17. $rate = 0;
  18. if ($this->boss == true) {
  19. $bossRank = 1.5;
  20. } else {
  21. $bossRank = 1;
  22. }
  23. if ($this->rank == 1) {
  24. $rate = 1;
  25. } elseif ($this->rank == 2) {
  26. $rate = 1.25;
  27. } elseif ($this->rank == 3) {
  28. $rate = 1.5;
  29. }
  30. $rate *= $bossRank;
  31. return $this->basicSalary * $rate;
  32. }
  33.  
  34. public function getCoffee()
  35. {
  36. if ($this->boss == true) {
  37. return $this->coffee * 2;
  38. } else {
  39. return $this->coffee;
  40. }
  41. }
  42.  
  43. public function getPages()
  44. {
  45. if ($this->boss) {
  46. return 0;
  47. } else {
  48. return $this->pages;
  49. }
  50. }
  51. }
  52.  
  53. class Manager extends Employee {
  54. protected $rank = 1;
  55. protected $basicSalary = 500;
  56. protected $coffee = 20;
  57. protected $pages = 200;
  58. protected $boss = false;
  59.  
  60. function __construct($rank, $boss) {
  61. $this->rank = $rank;
  62. $this->boss = $boss;
  63. }
  64. }
  65.  
  66. class MarketingSpecialist extends Employee {
  67. protected $rank = 1;
  68. protected $basicSalary = 400;
  69. protected $coffee = 15;
  70. protected $pages = 150;
  71. protected $boss = false;
  72.  
  73. function __construct($rank, $boss) {
  74. $this->rank = $rank;
  75. $this->boss = $boss;
  76. }
  77. }
  78.  
  79. class Engineer extends Employee {
  80. protected $rank = 1;
  81. protected $basicSalary = 200;
  82. protected $coffee = 5;
  83. protected $pages = 50;
  84. protected $boss = false;
  85.  
  86. function __construct($rank, $boss) {
  87. $this->rank = $rank;
  88. $this->boss = $boss;
  89. }
  90. }
  91.  
  92. class Analyst extends Employee {
  93. protected $rank = 1;
  94. protected $basicSalary = 800;
  95. protected $coffee = 50;
  96. protected $pages = 5;
  97. protected $boss = false;
  98.  
  99. function __construct($rank, $boss = false) {
  100. $this->rank = $rank;
  101. $this->boss = $boss;
  102. }
  103. }
  104.  
  105.  
  106. class Department {
  107. private $employees = [];
  108. private $name;
  109.  
  110. function __construct($name) {
  111. $this->name = $name;
  112. }
  113.  
  114. public function addEmployee($profession, $amount, $rank = 1, $boss = false)
  115. {
  116. for ($i=0; $i < $amount; $i++) {
  117. $this->employees[] = new $profession($rank, $boss);
  118. }
  119. }
  120.  
  121. public function getDepartmentName()
  122. {
  123. return $this->name;
  124. }
  125.  
  126. public function getEmployeesNumber()
  127. {
  128. return count($this->employees);
  129. }
  130.  
  131. public function getAllSalary()
  132. {
  133. $result = 0;
  134. foreach ($this->employees as $employee)
  135. $result += $employee->getSalary();
  136. return $result;
  137. }
  138.  
  139. public function getAllCoffee()
  140. {
  141. $result = 0;
  142. foreach ($this->employees as $employee)
  143. $result += $employee->getCoffee();
  144. return $result;
  145. }
  146.  
  147. public function getAllPages()
  148. {
  149. $result = 0;
  150. foreach ($this->employees as $employee)
  151. $result += $employee->getPages();
  152. return $result;
  153. }
  154. }
  155.  
  156. function padRight($string, $widthOfTableCell){
  157. $tableCell = $string . str_repeat(" ", $widthOfTableCell - mb_strlen($string));
  158. return $tableCell;
  159. }
  160.  
  161. function padLeft($string, $widthOfTableCell){
  162. $tableCell = str_repeat(" ", $widthOfTableCell - mb_strlen($string)) . $string;
  163. return $tableCell;
  164. }
  165.  
  166. function allIndex($departments) {
  167. $col1 = 15;
  168. $col2 = $col3 = $col4 = $col5 = $col6 = 12;
  169. $countedColumns = $col1 + $col2 + $col3 + $col4 + $col5 + $col6;
  170. $departmentsNumber = count($departments);
  171. $allEmployees = 0;
  172. $allSalary = 0;
  173. $allCoffee = 0;
  174. $allPages = 0;
  175. $averageMoneyPerPages = 0;
  176.  
  177. echo padRight("Департамент", $col1) .
  178. padLeft("сотр.", $col2) .
  179. padLeft("тугр.", $col3) .
  180. padLeft("кофе", $col4) .
  181. padLeft("стр.", $col5) .
  182. padLeft("тугр./стр.", $col6) ."<br>\n";
  183.  
  184. echo str_repeat("-", $countedColumns) ."<br>\n";
  185.  
  186. foreach ($departments as $number => $department) {
  187. $departmentName = $departments[$number]->getDepartmentName();
  188. $employeesNumber = $departments[$number]->getEmployeesNumber();
  189. $allDepartmentSalary = $departments[$number]->getAllSalary();
  190. $allDepartmentCoffee = $departments[$number]->getAllCoffee();
  191. $allDepartmentPages = $departments[$number]->getAllPages();
  192. $moneyPerPages = round($allDepartmentSalary / $allDepartmentPages, 2);
  193.  
  194. echo padRight($departmentName, $col1) .
  195. padLeft($employeesNumber, $col2) .
  196. padLeft($allDepartmentSalary, $col3) .
  197. padLeft($allDepartmentCoffee, $col4) .
  198. padLeft($allDepartmentPages, $col5) .
  199. padLeft($moneyPerPages, $col6) ."<br>\n";
  200.  
  201. $allEmployees += $employeesNumber;
  202. $allSalary += $allDepartmentSalary;
  203. $allCoffee += $allDepartmentCoffee;
  204. $allPages += $allDepartmentPages;
  205. $averageMoneyPerPages += $moneyPerPages;
  206. }
  207.  
  208. echo str_repeat("-", $countedColumns) ."<br>\n";
  209.  
  210. echo padRight("Среднее", $col1) .
  211. padLeft($allEmployees / $departmentsNumber, $col2) .
  212. padLeft($allSalary / $departmentsNumber, $col3) .
  213. padLeft($allCoffee / $departmentsNumber, $col4) .
  214. padLeft($allPages / $departmentsNumber, $col5) .
  215. padLeft(round($averageMoneyPerPages / $departmentsNumber, 2), $col6) ."<br>\n";
  216.  
  217. echo padRight("Всего", $col1) .
  218. padLeft($allEmployees, $col2) .
  219. padLeft($allSalary, $col3) .
  220. padLeft($allCoffee, $col4) .
  221. padLeft($allPages, $col5) .
  222. padLeft($averageMoneyPerPages, $col6) ."<br>\n";
  223.  
  224. }
  225.  
  226. $purchaseDepartment = new Department("Закупок");
  227.  
  228. $purchaseDepartment->addEmployee("Manager", 9);
  229. $purchaseDepartment->addEmployee("Manager", 3, 2);
  230. $purchaseDepartment->addEmployee("Manager", 2, 3);
  231. $purchaseDepartment->addEmployee("MarketingSpecialist", 2, 1);
  232. $purchaseDepartment->addEmployee("Manager", 1, 2, true);
  233.  
  234. $saleDepartment = new Department("Продаж");
  235.  
  236. $saleDepartment->addEmployee("Manager", 12);
  237. $saleDepartment->addEmployee("MarketingSpecialist", 6);
  238. $saleDepartment->addEmployee("Analyst", 3);
  239. $saleDepartment->addEmployee("Analyst", 2, 2);
  240. $saleDepartment->addEmployee("Manager", 1, 2, true);
  241.  
  242. $advertisingDepartment = new Department("Рекламы");
  243.  
  244. $advertisingDepartment->addEmployee("MarketingSpecialist", 15);
  245. $advertisingDepartment->addEmployee("MarketingSpecialist", 10, 2);
  246. $advertisingDepartment->addEmployee("Manager", 8);
  247. $advertisingDepartment->addEmployee("Engineer", 2);
  248. $advertisingDepartment->addEmployee("Manager", 1, 3, true);
  249.  
  250. $logisticsDepartment = new Department("Логистики");
  251.  
  252. $logisticsDepartment->addEmployee("Manager", 13);
  253. $logisticsDepartment->addEmployee("Manager", 5, 2);
  254. $logisticsDepartment->addEmployee("Engineer", 5);
  255. $logisticsDepartment->addEmployee("Manager", 1, 1, true);
  256.  
  257. $departments = array($purchaseDepartment, $saleDepartment, $advertisingDepartment, $logisticsDepartment);
  258.  
  259. allIndex($departments);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Департамент           сотр.       тугр.        кофе        стр.  тугр./стр.<br>
---------------------------------------------------------------------------<br>
Закупок                  17      9612.5         350        3100         3.1<br>
Продаж                   24     13737.5         620        3325        4.13<br>
Рекламы                  36       16525         585        5450        3.03<br>
Логистики                24       11375         425        3850        2.95<br>
---------------------------------------------------------------------------<br>
Среднее               25.25     12812.5         495     3931.25         3.3<br>
Всего                   101       51250        1980       15725       13.21<br>