fork download
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Саша
  5.  * Date: 04.05.2016
  6.  * Time: 10:59
  7.  */
  8.  
  9. abstract 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. class Company {
  157. public $allEmployees = 0;
  158. public $allCoffee = 0;
  159. public $allSalary = 0;
  160. public $allPages = 0;
  161. public $averageMoneyPerPages = 0;
  162.  
  163. public $averageEmployees = 0;
  164. public $averageCoffee = 0;
  165. public $averageSalary = 0;
  166. public $averagePages = 0;
  167. public $overallMoneyPerPages = 0;
  168.  
  169. public function __construct($departments)
  170. {
  171. }
  172. public function getAverageEmployees($departments){
  173. return $this->getAllEmployees($departments) / count($departments);
  174. }
  175. public function getAverageSalary($departments){
  176. return $this->getAllSalary($departments) / count($departments);
  177. }
  178. public function getAverageCoffee($departments){
  179. return $this->getAllCoffee($departments) / count($departments);
  180. }
  181. public function getAveragePages($departments){
  182. return $this->getAllPages($departments) / count($departments);
  183. }
  184. public function getAllEmployees($departments) {
  185. $allEmployees = 0;
  186. foreach ($departments as $number => $department) {
  187. $employeesNumber = $departments[$number]->getEmployeesNumber();
  188. $allEmployees += $employeesNumber;
  189. };
  190. return $allEmployees;
  191. }
  192. public function getAllCoffee($departments) {
  193. $allCoffee = 0;
  194. foreach ($departments as $number => $department) {
  195. $allCoffee += $departments[$number]->getAllCoffee();
  196. }
  197. return $allCoffee;
  198. }
  199. public function getAllSalary($departments) {
  200. $allSalary = 0;
  201. foreach ($departments as $number => $department) {
  202. $allSalary += $departments[$number]->getAllSalary();
  203. }
  204. return $allSalary;
  205. }
  206. public function getAllPages($departments) {
  207. $allPages = 0;
  208. foreach ($departments as $number => $department) {
  209. $allPages += $departments[$number]->getAllPages();
  210. }
  211. return $allPages;
  212. }
  213. public function getAverageMoneyPerPages($allSalary, $allPages) {
  214. $averageMoneyPerPages = round($allSalary / $allPages, 2);
  215. return $averageMoneyPerPages;
  216. }
  217. public function getAllAverageMoneyPerPages($departments) {
  218. $allMoneyPerPages = 0;
  219. foreach ($departments as $number => $department) {
  220. $allMoneyPerPages += $this->getAllSalary($departments) / $this->getAllPages($departments);
  221. }
  222. return round($allMoneyPerPages, 2);
  223. }
  224.  
  225. }
  226.  
  227. function padRight($string, $widthOfTableCell){
  228. $tableCell = $string . str_repeat(" ", $widthOfTableCell - mb_strlen($string));
  229. return $tableCell;
  230. }
  231.  
  232. function padLeft($string, $widthOfTableCell){
  233. $tableCell = str_repeat(" ", $widthOfTableCell - mb_strlen($string)) . $string;
  234. return $tableCell;
  235. }
  236.  
  237. function allIndex($departments) {
  238. $col1 = 15;
  239. $col2 = $col3 = $col4 = $col5 = $col6 = 12;
  240. $countedColumns = $col1 + $col2 + $col3 + $col4 + $col5 + $col6;
  241. $departmentsNumber = count($departments);
  242. $allEmployees = 0;
  243. $allSalary = 0;
  244. $allCoffee = 0;
  245. $allPages = 0;
  246. $averageMoneyPerPages = 0;
  247.  
  248. echo padRight("Департамент", $col1) .
  249. padLeft("сотр.", $col2) .
  250. padLeft("тугр.", $col3) .
  251. padLeft("кофе", $col4) .
  252. padLeft("стр.", $col5) .
  253. padLeft("тугр./стр.", $col6) ."<br>\n";
  254.  
  255. echo str_repeat("-", $countedColumns) ."<br>\n";
  256.  
  257. foreach ($departments as $number => $department) {
  258. $departmentName = $departments[$number]->getDepartmentName();
  259. $employeesNumber = $departments[$number]->getEmployeesNumber();
  260. $allDepartmentSalary = $departments[$number]->getAllSalary();
  261. $allDepartmentCoffee = $departments[$number]->getAllCoffee();
  262. $allDepartmentPages = $departments[$number]->getAllPages();
  263. $moneyPerPages = round($allDepartmentSalary / $allDepartmentPages, 2);
  264.  
  265. echo padRight($departmentName, $col1) .
  266. padLeft($employeesNumber, $col2) .
  267. padLeft($allDepartmentSalary, $col3) .
  268. padLeft($allDepartmentCoffee, $col4) .
  269. padLeft($allDepartmentPages, $col5) .
  270. padLeft($moneyPerPages, $col6) ."<br>\n";
  271.  
  272. $allEmployees += $employeesNumber;
  273. $allSalary += $allDepartmentSalary;
  274. $allCoffee += $allDepartmentCoffee;
  275. $allPages += $allDepartmentPages;
  276. $averageMoneyPerPages += $moneyPerPages;
  277. }
  278.  
  279. }
  280.  
  281. $purchaseDepartment = new Department("Закупок");
  282.  
  283. $purchaseDepartment->addEmployee("Manager", 9);
  284. $purchaseDepartment->addEmployee("Manager", 3, 2);
  285. $purchaseDepartment->addEmployee("Manager", 2, 3);
  286. $purchaseDepartment->addEmployee("MarketingSpecialist", 2, 1);
  287. $purchaseDepartment->addEmployee("Manager", 1, 2, true);
  288.  
  289. $saleDepartment = new Department("Продаж");
  290.  
  291. $saleDepartment->addEmployee("Manager", 12);
  292. $saleDepartment->addEmployee("MarketingSpecialist", 6);
  293. $saleDepartment->addEmployee("Analyst", 3);
  294. $saleDepartment->addEmployee("Analyst", 2, 2);
  295. $saleDepartment->addEmployee("Manager", 1, 2, true);
  296.  
  297. $advertisingDepartment = new Department("Рекламы");
  298.  
  299. $advertisingDepartment->addEmployee("MarketingSpecialist", 15);
  300. $advertisingDepartment->addEmployee("MarketingSpecialist", 10, 2);
  301. $advertisingDepartment->addEmployee("Manager", 8);
  302. $advertisingDepartment->addEmployee("Engineer", 2);
  303. $advertisingDepartment->addEmployee("Manager", 1, 3, true);
  304.  
  305. $logisticsDepartment = new Department("Логистики");
  306.  
  307. $logisticsDepartment->addEmployee("Manager", 13);
  308. $logisticsDepartment->addEmployee("Manager", 5, 2);
  309. $logisticsDepartment->addEmployee("Engineer", 5);
  310. $logisticsDepartment->addEmployee("Manager", 1, 1, true);
  311.  
  312. $departments = array($purchaseDepartment, $saleDepartment, $advertisingDepartment, $logisticsDepartment);
  313.  
  314. allIndex($departments);
  315.  
  316. $col1 = 15;
  317. $col2 = $col3 = $col4 = $col5 = $col6 = 12;
  318. $countedColumns = $col1 + $col2 + $col3 + $col4 + $col5 + $col6;
  319.  
  320. $vector = new Company($departments);
  321.  
  322. echo str_repeat("-", $countedColumns) ."<br>\n";
  323.  
  324. echo padRight("Среднее", $col1) .
  325. padLeft($vector->getAverageEmployees($departments), $col2) .
  326. padLeft($vector->getAverageSalary($departments), $col3) .
  327. padLeft($vector->getAverageCoffee($departments), $col4) .
  328. padLeft($vector->getAveragePages($departments), $col5) .
  329. padLeft($vector->getAverageMoneyPerPages($vector->getAllSalary($departments), $vector->getAllPages($departments)), $col6) ."<br>\n";
  330.  
  331. echo padRight("Всего", $col1) .
  332. padLeft($vector->getAllEmployees($departments), $col2) .
  333. padLeft($vector->getAllSalary($departments), $col3) .
  334. padLeft($vector->getAllCoffee($departments), $col4) .
  335. padLeft($vector->getAllPages($departments), $col5) .
  336. padLeft($vector->getAllAverageMoneyPerPages($departments), $col6) ."<br>\n";
Success #stdin #stdout 0.02s 52432KB
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.26<br>
Всего                   101       51250        1980       15725       13.04<br>