fork(2) download
  1. <?php
  2.  
  3. class Company {
  4.  
  5. public $departments = [];
  6.  
  7. public function addDepartment($department)
  8. {
  9.  
  10. array_push($this->departments, $department);
  11.  
  12. }
  13.  
  14. public function countTotalEmployees()
  15. {
  16.  
  17. $totalEmployees = 0;
  18. foreach ($this->departments as $department){
  19. $totalEmployees += $department->countEmployees($department->employees);
  20. }
  21. return $totalEmployees;
  22.  
  23. }
  24.  
  25. public function countTotalCoffeConsumption()
  26. {
  27.  
  28. $totalCoffeConsumption = 0;
  29. foreach ($this->departments as $department) {
  30. $totalCoffeConsumption += $department->countCoffeConusmption($department->employees);
  31. }
  32. return $totalCoffeConsumption;
  33.  
  34. }
  35.  
  36. public function countTotalSalary()
  37. {
  38.  
  39. $totalSalary = 0;
  40. foreach ($this->departments as $department) {
  41. $totalSalary += $department->countSalary($department->employees);
  42. }
  43. return $totalSalary;
  44.  
  45. }
  46.  
  47. public function countTotalReports()
  48. {
  49.  
  50. $totalReports = 0;
  51. foreach ($this->departments as $department) {
  52. $totalReports += $department->countReports($department->employees);
  53. }
  54. return $totalReports;
  55.  
  56. }
  57.  
  58. public function countTotalMainReports()
  59. {
  60.  
  61. $totalMainReports = 0;
  62. foreach ($this->departments as $department) {
  63. $totalMainReports += $department->countMainReports($department->employees);
  64. }
  65. return $totalMainReports;
  66.  
  67. }
  68.  
  69. public function countTotalBlueprints()
  70. {
  71.  
  72. $totalBlueprints = 0;
  73. foreach ($this->departments as $department) {
  74. $totalBlueprints += $department->countBlueprints($department->employees);
  75. }
  76. return $totalBlueprints;
  77.  
  78. }
  79.  
  80. }
  81.  
  82. class Department
  83. {
  84.  
  85. public $employees = [];
  86. public $name;
  87.  
  88. public function createEmployee($rank, $isBoss, $proffession)
  89. {
  90.  
  91. if($proffession == "Manager" ){
  92. array_push($this->employees, new Manager($rank, $isBoss, $proffession));
  93. } elseif ($proffession == "Marketolog") {
  94. array_push($this->employees, new Marketolog($rank, $isBoss, $proffession));
  95. } elseif ($proffession == "Engeneer") {
  96. array_push($this->employees, new Engeneer($rank, $isBoss, $proffession));
  97. } elseif ($proffession == "Analyst") {
  98. array_push($this->employees, new Analyst($rank, $isBoss, $proffession));
  99. }
  100.  
  101. }
  102.  
  103. public function deleteEmployee($rank, $isBoss, $proffession)
  104. {
  105.  
  106. foreach ($this->employees as $key => $employee){
  107. if($rank == $employee->rank && $isBoss == $employee->isBoss && $proffession == $employee->proffession) {
  108. unset($this->employees[$key]);
  109. break;
  110. }
  111. }
  112. }
  113.  
  114.  
  115. public function countEmployees()
  116. {
  117.  
  118. return count($this->employees);
  119.  
  120. }
  121.  
  122. public function countCoffeConusmption ()
  123. {
  124.  
  125. $dpCoffeConsumption = 0;
  126. foreach ($this->employees as $employee){
  127. $dpCoffeConsumption += $employee->countEmployeeCoffeConusmption ();
  128. }
  129. return $dpCoffeConsumption;
  130.  
  131. }
  132.  
  133. public function countSalary ()
  134. {
  135.  
  136. $dpSalary = 0;
  137. foreach ($this->employees as $employee) {
  138. $dpSalary += $employee->countEmployeeSalary();
  139. }
  140. return $dpSalary;
  141. }
  142.  
  143. public function countReports ()
  144. {
  145.  
  146. $dpReports = 0;
  147. foreach ($this->employees as $employee) {
  148. $dpReports += $employee->getReports();
  149. }
  150. return $dpReports;
  151. }
  152.  
  153. public function countBlueprints ()
  154. {
  155.  
  156. $dpBlueprints = 0;
  157. foreach ($this->employees as $employee) {
  158. $dpBlueprints += $employee->getBlueprints();
  159. }
  160. return $dpBlueprints;
  161. }
  162.  
  163. public function countMainReports ()
  164. {
  165.  
  166. $dpMainReports = 0;
  167. foreach ($this->employees as $employee) {
  168. $dpMainReports += $employee->getMainReports();
  169. }
  170. return $dpMainReports;
  171. }
  172.  
  173. }
  174.  
  175. abstract class Employee
  176. {
  177. function __construct ($rank, $isBoss, $proffession)
  178. {
  179. $this->isBoss = $isBoss;
  180. $this->rank = $rank;
  181. $this->proffession = $proffession;
  182.  
  183. }
  184.  
  185.  
  186. abstract function getProfession();
  187. protected abstract function getAmountOfCoffe();
  188. protected abstract function getBaseSalary();
  189. abstract function getReports();
  190. abstract function getMainReports();
  191. abstract function getBlueprints();
  192.  
  193.  
  194. public function countEmployeeCoffeConusmption ()
  195. {
  196.  
  197. $employeeCoffeConsumption = 0;
  198. if ($this->isBoss == true) {
  199. $employeeCoffeConsumption = $this->getAmountOfCoffe() * 2;
  200. } else {
  201. $employeeCoffeConsumption = $this->getAmountOfCoffe();
  202. }
  203. return $employeeCoffeConsumption;
  204.  
  205. }
  206.  
  207. public function countEmployeeSalary ()
  208. {
  209.  
  210. $dpSalary = 0;
  211. if ($this->rank == 3) {
  212. $dpSalary += $this->getBaseSalary() + ($this->getBaseSalary() * 0.5);
  213. } elseif ($this->rank == 2) {
  214. $dpSalary += $this->getBaseSalary() + ($this->getBaseSalary() * 0.25);
  215. } else {
  216. $dpSalary += $this->getBaseSalary();
  217. }
  218. return $dpSalary;
  219.  
  220. }
  221.  
  222.  
  223.  
  224. }
  225.  
  226. class Manager extends Employee
  227. {
  228.  
  229. function getProfession()
  230. {
  231.  
  232. return $proffession = "Manager";
  233.  
  234. }
  235.  
  236. protected function getBaseSalary()
  237. {
  238.  
  239. return $baseSalary = 500;
  240.  
  241. }
  242. protected function getAmountOfCoffe()
  243. {
  244.  
  245. return $amountOfCoffe = 25;
  246.  
  247. }
  248.  
  249. function getReports()
  250. {
  251.  
  252. return $reports = 200;
  253.  
  254. }
  255.  
  256. function getMainReports()
  257. {
  258.  
  259. return $mainReports = 0;
  260.  
  261. }
  262.  
  263. function getBlueprints()
  264. {
  265.  
  266. return $blueprints = 0;
  267.  
  268. }
  269.  
  270. }
  271.  
  272. class Engeneer extends Employee
  273. {
  274.  
  275. function getProfession()
  276. {
  277.  
  278. return $proffession = "Engeneer";
  279.  
  280. }
  281.  
  282. protected function getBaseSalary()
  283. {
  284.  
  285. return $baseSalary = 200;
  286.  
  287. }
  288. protected function getAmountOfCoffe()
  289. {
  290.  
  291. return $amountOfCoffe = 5;
  292.  
  293. }
  294.  
  295. function getReports()
  296. {
  297.  
  298. return $reports = 0;
  299.  
  300. }
  301.  
  302. function getMainReports()
  303. {
  304.  
  305. return $mainReports = 0;
  306.  
  307. }
  308.  
  309. function getBlueprints()
  310. {
  311.  
  312. return $blueprints = 50;
  313.  
  314. }
  315.  
  316. }
  317.  
  318. class Marketolog extends Employee
  319. {
  320.  
  321. function getProfession()
  322. {
  323.  
  324. return $proffession = "Marketolog";
  325.  
  326. }
  327.  
  328. protected function getBaseSalary()
  329. {
  330.  
  331. return $baseSalary = 400;
  332.  
  333. }
  334. protected function getAmountOfCoffe()
  335. {
  336.  
  337. return $amountOfCoffe = 15;
  338.  
  339. }
  340.  
  341. function getReports()
  342. {
  343.  
  344. return $reports = 150;
  345.  
  346. }
  347.  
  348. function getMainReports()
  349. {
  350.  
  351. return $mainReports = 0;
  352.  
  353. }
  354.  
  355. function getBlueprints()
  356. {
  357.  
  358. return $blueprints = 0;
  359.  
  360. }
  361.  
  362. }
  363.  
  364. class Analyst extends Employee
  365. {
  366.  
  367. function getProfession()
  368. {
  369.  
  370. return $proffession = "Analyst";
  371.  
  372. }
  373.  
  374. protected function getBaseSalary()
  375. {
  376.  
  377. return $baseSalary = 800;
  378. // return $baseSalary = 1100; // Значение для второй антикризисной меры
  379.  
  380.  
  381. }
  382. protected function getAmountOfCoffe()
  383. {
  384.  
  385. return $amountOfCoffe = 50;
  386. // return $amountOfCoffe = 75; // Значение для второй антикризисной меры
  387. }
  388.  
  389. function getReports()
  390. {
  391.  
  392. return $reports = 0;
  393.  
  394. }
  395.  
  396. function getMainReports()
  397. {
  398.  
  399. return $mainReports = 5;
  400.  
  401. }
  402.  
  403. function getBlueprints()
  404. {
  405.  
  406. return $blueprints = 0;
  407.  
  408. }
  409.  
  410. }
  411.  
  412. class Antycrysis1
  413. {
  414.  
  415. private function countEngeneers($department) : int
  416. {
  417. $numberOfEngneers = 0;
  418. foreach($department->employees as $employee) {
  419. if ($employee->proffession == "Engeneer") {
  420. $numberOfEngneers++;
  421. }
  422. }
  423. return $numberOfEngneers;
  424. }
  425.  
  426. public function fireEngeneers($department)
  427. {
  428.  
  429. for($i = 0; $i < round($this->countEngeneers($department) * 0.4, PHP_ROUND_HALF_UP); $i++) {
  430. $department->deleteEmployee(1, 0, "Engeneer");
  431. }
  432. }
  433.  
  434. }
  435.  
  436. class Antycrisys2
  437. {
  438.  
  439. public function replaseBoss($department)
  440. {
  441.  
  442. foreach ($department->employees as $employee){
  443. if ($employee->isBoss == 1 && $employee->proffession != "Analyst" ){
  444. $employee->isBoss = 0;
  445. }
  446. }
  447. foreach ($department->employees as $employee){
  448. if ($employee->isBoss == 0 && $employee->proffession == "Analyst" && $employee->rank == 3) {
  449. $employee->isBoss = 1;
  450. break;
  451. }
  452. }
  453. foreach ($department->employees as $employee){
  454. if ($employee->isBoss == 0 && $employee->proffession == "Analyst" && $employee->rank == 2) {
  455. $employee->isBoss = 1;
  456. break;
  457. }
  458. }
  459. foreach ($department->employees as $employee){
  460. if ($employee->isBoss == 0 && $employee->proffession == "Analyst" && $employee->rank == 1) {
  461. $employee->isBoss = 1;
  462. break;
  463. }
  464. }
  465.  
  466. }
  467.  
  468. }
  469.  
  470. class Antycrisys3
  471. {
  472.  
  473. public function promoteManagers($department)
  474. {
  475.  
  476. for($i = 0; $i < round($this->countManagers2($department) * 0.5); $i++) {
  477. $this->riseManagers2($department);
  478. }
  479. for($i = 0; $i < round($this->countManagers1($department) * 0.5); $i++) {
  480. $this->riseManagers1($department);
  481. }
  482.  
  483. }
  484.  
  485. private function countManagers1($department) : int
  486. {
  487.  
  488. $numberOfManagers1 = 0;
  489.  
  490. foreach($department->employees as $employee) {
  491. if ($employee->proffession == "Manager" && $employee->rank == 1 ) {
  492.  
  493. $numberOfManagers1++;
  494. }
  495. }
  496. return $numberOfManagers1;
  497.  
  498. }
  499. private function countManagers2($department) : int
  500. {
  501.  
  502. $numberOfManagers2 = 0;
  503. foreach($department->employees as $employee) {
  504. if ($employee->proffession == "Manager" && $employee->rank == 2 ) {
  505. $numberOfManagers2++;
  506. }
  507. }
  508. return $numberOfManagers2;
  509.  
  510. }
  511.  
  512. private function riseManagers1($department)
  513. {
  514. foreach ($department->employees as $employee){
  515. if ($employee->proffession == "Manager" && $employee->rank == 1){
  516. $employee->rank = 2;
  517. break;
  518. }
  519. }
  520.  
  521. }
  522. private function riseManagers2($department)
  523. {
  524. foreach ($department->employees as $employee){
  525. if ($employee->proffession == "Manager" && $employee->rank == 2){
  526. $employee->rank = 3;
  527. break;
  528. }
  529. }
  530.  
  531. }
  532. }
  533.  
  534.  
  535. $purchaseDepartment = new Department();
  536. $purchaseDepartment->name = "Purchase Department";
  537. $purchaseDepartment->createEmployee(2, 1, "Manager");
  538. for($i = 0; $i < 9; $i++){
  539. $purchaseDepartment->createEmployee(1, 0, "Manager");
  540. }
  541. for($i = 0; $i < 3; $i++){
  542. $purchaseDepartment->createEmployee(2, 0, "Manager");
  543. }
  544. for($i = 0; $i < 2; $i++){
  545. $purchaseDepartment->createEmployee(3, 0, "Manager");
  546. }
  547. for($i = 0; $i < 2; $i++){
  548. $purchaseDepartment->createEmployee(1, 0, "Marketolog");
  549. }
  550.  
  551. $sellersDepartment = new Department();
  552. $sellersDepartment->name = "Sellers Department";
  553. $sellersDepartment->createEmployee(2, 1, "Marketolog");
  554. for($i = 0; $i < 12; $i++){
  555. $sellersDepartment->createEmployee(1, 0, "Manager");
  556. }
  557. for($i = 0; $i < 6; $i++){
  558. $sellersDepartment->createEmployee(1, 0, "Marketolog");
  559. }
  560. for($i = 0; $i < 3; $i++){
  561. $sellersDepartment->createEmployee(1, 0, "Analyst");
  562. }
  563. for($i = 0; $i < 2; $i++){
  564. $sellersDepartment->createEmployee(2, 0, "Analyst");
  565. }
  566. for($i = 0; $i < 2; $i++){
  567. $sellersDepartment->createEmployee(3, 0, "Analyst");
  568. }
  569.  
  570. $marketingDepartment = new Department();
  571. $marketingDepartment->name = "Marketing Department";
  572. $marketingDepartment->createEmployee(3, 1, "Marketolog");
  573. for($i = 0; $i < 15; $i++){
  574. $marketingDepartment->createEmployee(1, 0, "Marketolog");
  575. }
  576. for($i = 0; $i < 10; $i++){
  577. $marketingDepartment->createEmployee(2, 0, "Marketolog");
  578. }
  579. for($i = 0; $i < 8; $i++){
  580. $marketingDepartment->createEmployee(1, 0, "Manager");
  581. }
  582. for($i = 0; $i < 2; $i++){
  583. $marketingDepartment->createEmployee(1, 0, "Engeneer");
  584. }
  585.  
  586. $logisticDepartment = new Department();
  587. $logisticDepartment->name = "Logistic Department";
  588. $logisticDepartment->createEmployee(1, 1, "Manager");
  589. for($i = 0; $i < 13; $i++){
  590. $logisticDepartment->createEmployee(1, 0, "Manager");
  591. }
  592. for($i = 0; $i < 5; $i++){
  593. $logisticDepartment->createEmployee(2, 0, "Manager");
  594. }
  595. for($i = 0; $i < 5; $i++){
  596. $logisticDepartment->createEmployee(1, 0, "Engeneer");
  597. }
  598.  
  599. $company = new Company;
  600. $company->addDepartment($purchaseDepartment);
  601. $company->addDepartment($sellersDepartment);
  602. $company->addDepartment($marketingDepartment);
  603. $company->addDepartment($logisticDepartment);
  604.  
  605. /*$antycrysis1 = new Antycrysis1();
  606. $antycrysis1->fireEngeneers($marketingDepartment); // Для первой антикризиной меры
  607. */
  608.  
  609. /*$antycrysis2 = new Antycrisys2();
  610. $antycrysis2->replaseBoss($sellersDepartment); // Для второй антикризиной меры
  611. */
  612.  
  613. /*$antycrysis3 = new Antycrisys3();
  614. $antycrysis3->promoteManagers($purchaseDepartment); // Для третьей антикризиной меры
  615. */
  616.  
  617. foreach ($company->departments as $department){
  618. echo $department->name . "\n" .
  619. "Employees: " . $department->countEmployees() . "\n" .
  620. "Coffe: " . $department->countCoffeConusmption() . "\n" .
  621. "Salary: " . $department->countSalary() . "\n" .
  622. "Reports: " . $department->countReports() . "\n" .
  623. "MainReports: " . $department->countMainReports() . "\n" .
  624. "Blueprints: " . $department->countBlueprints() . "\n" ;
  625.  
  626. echo str_repeat("__", 30) . "\n";
  627. }
  628.  
  629. echo "Total Employees: " . $company->countTotalEmployees() . "\n" .
  630. "Total coffe: " . $company->countTotalCoffeConsumption() . "\n" .
  631. "Total salary: " . $company->countTotalSalary() . "\n" .
  632. "Total reports: " . $company->countTotalReports() . "\n" .
  633. "Total main reports: " . $company->countTotalMainReports() . "\n" .
  634. "Total blueprints: " . $company->countTotalBlueprints() . "\n";
  635.  
  636. echo str_repeat("__", 30) . "\n";
  637.  
  638. echo "Avarage Employees: " . round($company->countTotalEmployees() / count($company->departments), 2) . "\n" .
  639. "Avarage coffe: " . round($company->countTotalCoffeConsumption() / count($company->departments), 2) . "\n" .
  640. "Avarage salary: " . round($company->countTotalSalary() / count($company->departments), 2) . "\n" .
  641. "Avarage reports: " . round($company->countTotalReports() / count($company->departments), 2) . "\n" .
  642. "Avarage main reports: " . round($company->countTotalMainReports() / count($company->departments), 2) ."\n" .
  643. "Avarage blueprints: " . round($company->countTotalBlueprints() / count($company->departments), 2) . "\n";
Success #stdin #stdout 0.03s 23488KB
stdin
Standard input is empty
stdout
Purchase Department
Employees: 17
Coffe: 430
Salary: 9300
Reports: 3300
MainReports: 0
Blueprints: 0
____________________________________________________________
Sellers Department
Employees: 26
Coffe: 770
Salary: 15700
Reports: 3450
MainReports: 35
Blueprints: 0
____________________________________________________________
Marketing Department
Employees: 36
Coffe: 615
Salary: 16000
Reports: 5500
MainReports: 0
Blueprints: 100
____________________________________________________________
Logistic Department
Employees: 24
Coffe: 525
Salary: 11125
Reports: 3800
MainReports: 0
Blueprints: 250
____________________________________________________________
Total Employees: 103
Total coffe: 2340
Total salary: 52125
Total reports: 16050
Total main reports: 35
Total blueprints: 350
____________________________________________________________
Avarage Employees: 25.75
Avarage coffe: 585
Avarage salary: 13031.25
Avarage reports: 4012.5
Avarage main reports: 8.75
Avarage blueprints: 87.5