fork download
  1. <?php
  2.  
  3. abstract class Employee
  4. {
  5.  
  6. public function __construct($amountOfCoffe, $salary, $rank)
  7. {
  8.  
  9. $this->amountOfCoffe = $amountOfCoffe;
  10. $this->salary = $salary;
  11. $this->rank = $rank;
  12.  
  13. }
  14.  
  15. public function getSalaryFromRank()
  16. {
  17.  
  18. if($this->rank == 3){
  19. $rankSalary = $this->salary + ($this->salary * 0.5);
  20. } elseif ($this->rank == 2){
  21. $rankSalary = $this->salary + ($this->salary * 0.25);
  22. } elseif ($this->rank == 1){
  23. $rankSalary = $this->salary;
  24. } else {
  25. echo 'SHIEEEEEEET';
  26. }
  27. return $rankSalary;
  28. }
  29.  
  30. }
  31.  
  32. class Boss extends Employee
  33. {
  34.  
  35. public function getBossSalary()
  36. {
  37.  
  38. $bossSalary = $this->getSalaryFromRank() + ($this->getSalaryFromRank() * 0.5);
  39. return $bossSalary;
  40.  
  41. }
  42.  
  43. public function getBossCoffeConsumption()
  44. {
  45.  
  46. $bossCoffeConsumption = $this->amountOfCoffe * 2;
  47. return $bossCoffeConsumption;
  48.  
  49. }
  50.  
  51. }
  52.  
  53. class Worker extends Employee
  54. {
  55. public $reports;
  56. public $blueprints;
  57. public $mainReports;
  58.  
  59. public function getWorkerSalary()
  60. {
  61.  
  62. $workerSalary = $this->getSalaryFromRank();
  63. return $workerSalary;
  64.  
  65. }
  66.  
  67.  
  68. }
  69.  
  70. class Manager extends Worker
  71. {
  72.  
  73. public $reports = 200;
  74.  
  75. }
  76.  
  77. class Engeneer extends Worker
  78. {
  79.  
  80. public $blueprints = 50;
  81.  
  82. }
  83.  
  84. class Analyst extends Worker
  85. {
  86.  
  87. public $mainReports = 5;
  88.  
  89. }
  90.  
  91. class Marcketolog extends Worker
  92. {
  93.  
  94. public $reports = 150;
  95.  
  96. }
  97.  
  98.  
  99.  
  100. function countAllWorkers ($array) {
  101.  
  102. $workersInDepartment = count($array[1]) + 1;
  103. return $workersInDepartment;
  104.  
  105. }
  106.  
  107. function countAllSalary ($array) {
  108.  
  109. $departmentSalary = 0;
  110. $departmentSalary += $array[0]->getBossSalary();
  111. foreach ($array[1] as $worker) {
  112. $departmentSalary += $worker->getWorkerSalary();
  113. }
  114. return $departmentSalary;
  115. }
  116.  
  117. function departmentCoffeConsumption ($array) {
  118.  
  119. $departmentCoffe = 0;
  120. $departmentCoffe += $array[0]->getBossCoffeConsumption();
  121. foreach ($array[1] as $worker) {
  122. $departmentCoffe += $worker->amountOfCoffe;
  123. }
  124. return $departmentCoffe;
  125. }
  126.  
  127. function countDepartmentReports ($array) {
  128.  
  129. $departmentReports = 0;
  130. foreach ($array[1] as $worker) {
  131. $departmentReports += $worker->reports;
  132. }
  133. return $departmentReports;
  134. }
  135.  
  136. function countDepartmentMainReports ($array) {
  137.  
  138. $departmentMainReports = 0;
  139. foreach ($array[1] as $worker) {
  140. $departmentMainReports += $worker->mainReports;
  141. }
  142. return $departmentMainReports;
  143. }
  144.  
  145. function countDepartmentBlueprints ($array) {
  146.  
  147. $departmentBlueprints = 0;
  148. foreach ($array[1] as $worker) {
  149. $departmentBlueprints += $worker->blueprints;
  150. }
  151. return $departmentBlueprints;
  152. }
  153.  
  154. function allPages ($array) {
  155.  
  156. $departmentPages = countDepartmentBlueprints ($array) + countDepartmentReports ($array) + countDepartmentMainReports ($array);
  157. return $departmentPages;
  158.  
  159. }
  160.  
  161. function pageCost ($array) {
  162.  
  163. $pagesMoneyRatio = 0;
  164. $pagesMoneyRatio = countAllSalary($array) / allPages($array);
  165. return $pagesMoneyRatio = round($pagesMoneyRatio, 2);
  166.  
  167. }
  168.  
  169. function totalEmployees($array) {
  170.  
  171. $totalWorkers = 0;
  172. foreach ($array as $department) {
  173. $totalWorkers += countAllWorkers($department);
  174. }
  175. return $totalWorkers;
  176.  
  177. }
  178.  
  179. function totalSalary ($array) {
  180.  
  181. $departmentsSalary = 0;
  182. foreach ($array as $department) {
  183. $departmentsSalary += $department[0]->getBossSalary();
  184. foreach ($department[1] as $worker) {
  185. $departmentsSalary += $worker->getWorkerSalary();
  186. }
  187. }
  188. return $departmentsSalary;
  189. }
  190.  
  191. function totalCoffe ($array) {
  192.  
  193. $departmentsCoffe = 0;
  194. foreach ($array as $department) {
  195. $departmentsCoffe += $department[0]->getBossCoffeConsumption();
  196. foreach ($department[1] as $worker) {
  197. $departmentsCoffe += $worker->amountOfCoffe;
  198. }
  199. }
  200. return $departmentsCoffe;
  201.  
  202. }
  203.  
  204. function totalPages ($array) {
  205.  
  206. $departmentsPages = 0;
  207. foreach ($array as $department) {
  208. $departmentsPages += allPages($department);
  209. }
  210. return $departmentsPages;
  211.  
  212. }
  213.  
  214. function totalPageCost ($array) {
  215.  
  216. $departmentsMoneyPagesRatio = 0;
  217.  
  218. $departmentsMoneyPagesRatio = totalSalary($array) / totalPages($array);
  219.  
  220. return $departmentsMoneyPagesRatio = round($departmentsMoneyPagesRatio, 2);
  221.  
  222. }
  223.  
  224. function avarageEmployees ($array) {
  225.  
  226. $avarageEmployees = 0;
  227. $avarageEmployees = totalEmployees($array) / count($array);
  228. return $avarageEmployees = round($avarageEmployees);
  229. }
  230.  
  231. function avarageSalary ($array) {
  232.  
  233. $avarageSalary = 0;
  234. $avarageSalary = totalSalary($array) / count($array);
  235. return $avarageSalary = round($avarageSalary, 2);
  236.  
  237. }
  238.  
  239. function avaragePages ($array) {
  240.  
  241. $avaragePages = 0;
  242. $avaragePages = totalPages($array) / count($array);
  243. return $avaragePages = round($avaragePages);
  244.  
  245. }
  246.  
  247. function avarageCoffe ($array) {
  248.  
  249. $avarageCoffe = 0;
  250. $avarageCoffe = totalCoffe($array) / count($array);
  251. return $avarageCoffe = round($avarageCoffe, 1);
  252.  
  253. }
  254.  
  255. function avaragePageCost ($array) {
  256.  
  257. $avaragePageCost = 0;
  258. $avaragePageCost = totalSalary($array) / totalPages($array);
  259. return $avaragePageCost = round($avaragePageCost, 2);
  260.  
  261. }
  262.  
  263. function padRight($string, $length)
  264. {
  265.  
  266. $string = str_pad ($string, $length, " ");
  267. return $string;
  268.  
  269. }
  270.  
  271. function padLeft($string, $length)
  272. {
  273.  
  274. $string = str_pad ($string, $length, " ", STR_PAD_LEFT);
  275. return $string;
  276.  
  277. }
  278.  
  279.  
  280. $MarketingBoss = new Boss(20, 500, 3);
  281. $logisticBoss = new Boss(20, 500, 1);
  282. $sellersBoss = new Boss(20, 500, 2);
  283. $purhaseBoss = new Boss(20, 500, 2);
  284.  
  285. $purchaseDepartmentWorkers = [
  286. $pDM1 = new Manager(20, 500, 1),
  287. $pDM2 = new Manager(20, 500, 1),
  288. $pDM3 = new Manager(20, 500, 1),
  289. $pDM4 = new Manager(20, 500, 1),
  290. $pDM5 = new Manager(20, 500, 1),
  291. $pDM6 = new Manager(20, 500, 1),
  292. $pDM7 = new Manager(20, 500, 1),
  293. $pDM8 = new Manager(20, 500, 1),
  294. $pDM9 = new Manager(20, 500, 1),
  295. $pDM10 = new Manager(20, 500, 2),
  296. $pDM11 = new Manager(20, 500, 2),
  297. $pDM12 = new Manager(20, 500, 2),
  298. $pDM13 = new Manager(20, 500, 3),
  299. $pDM14 = new Manager(20, 500, 3),
  300. $pDMa1 = new Marcketolog(15, 400, 1),
  301. $pDMa2 = new Marcketolog(15, 400, 1),
  302. ];
  303.  
  304. $sellersDepartmentWorkers = [
  305. $sDM1 = new Manager(20, 500, 1),
  306. $sDM2 = new Manager(20, 500, 1),
  307. $sDM3 = new Manager(20, 500, 1),
  308. $sDM4 = new Manager(20, 500, 1),
  309. $sDM5 = new Manager(20, 500, 1),
  310. $sDM6 = new Manager(20, 500, 1),
  311. $sDM7 = new Manager(20, 500, 1),
  312. $sDM8 = new Manager(20, 500, 1),
  313. $sDM9 = new Manager(20, 500, 1),
  314. $sDM10 = new Manager(20, 500, 1),
  315. $sDM11 = new Manager(20, 500, 1),
  316. $sDM12 = new Manager(20, 500, 1),
  317. $sDMa1 = new Marcketolog(15, 400, 1),
  318. $sDMa2 = new Marcketolog(15, 400, 1),
  319. $sDMa3 = new Marcketolog(15, 400, 1),
  320. $sDMa4 = new Marcketolog(15, 400, 1),
  321. $sDMa5 = new Marcketolog(15, 400, 1),
  322. $sDMa6 = new Marcketolog(15, 400, 1),
  323. $sDAn1 = new Analyst(50, 800, 1),
  324. $sDAn2 = new Analyst(50, 800, 1),
  325. $sDAn3 = new Analyst(50, 800, 1),
  326. $sDAn4 = new Analyst(50, 800, 2),
  327. $sDAn5 = new Analyst(50, 800, 2),
  328.  
  329. ];
  330.  
  331. $marketingDepartmentWorkers = [
  332. $mDMa1 = new Marcketolog(15, 400, 1),
  333. $mDMa2 = new Marcketolog(15, 400, 1),
  334. $mDMa3 = new Marcketolog(15, 400, 1),
  335. $mDMa4 = new Marcketolog(15, 400, 1),
  336. $mDMa5 = new Marcketolog(15, 400, 1),
  337. $mDMa6 = new Marcketolog(15, 400, 1),
  338. $mDMa7 = new Marcketolog(15, 400, 1),
  339. $mDMa8 = new Marcketolog(15, 400, 1),
  340. $mDMa9 = new Marcketolog(15, 400, 1),
  341. $mDMa10 = new Marcketolog(15, 400, 1),
  342. $mDMa11 = new Marcketolog(15, 400, 1),
  343. $mDMa12 = new Marcketolog(15, 400, 1),
  344. $mDMa13 = new Marcketolog(15, 400, 1),
  345. $mDMa14 = new Marcketolog(15, 400, 1),
  346. $mDMa15 = new Marcketolog(15, 400, 1),
  347. $mDMa16 = new Marcketolog(15, 400, 2),
  348. $mDMa17 = new Marcketolog(15, 400, 2),
  349. $mDMa18 = new Marcketolog(15, 400, 2),
  350. $mDMa19 = new Marcketolog(15, 400, 2),
  351. $mDMa20 = new Marcketolog(15, 400, 2),
  352. $mDMa21 = new Marcketolog(15, 400, 2),
  353. $mDMa22 = new Marcketolog(15, 400, 2),
  354. $mDMa23 = new Marcketolog(15, 400, 2),
  355. $mDMa24 = new Marcketolog(15, 400, 2),
  356. $mDMa25 = new Marcketolog(15, 400, 2),
  357. $mDM1 = new Manager(20, 500, 1),
  358. $mDM2 = new Manager(20, 500, 1),
  359. $mDM3 = new Manager(20, 500, 1),
  360. $mDM4 = new Manager(20, 500, 1),
  361. $mDM5 = new Manager(20, 500, 1),
  362. $mDM6 = new Manager(20, 500, 1),
  363. $mDM7 = new Manager(20, 500, 1),
  364. $mDM8 = new Manager(20, 500, 1),
  365. $mDEn1 = new Engeneer(5, 200, 1),
  366. $mDEn2 = new Engeneer(5, 200, 1),
  367. ];
  368.  
  369. $logisticDepartmentWorkers = [
  370. $lDM1 = new Manager(15, 500, 1),
  371. $lDM2 = new Manager(20, 500, 1),
  372. $lDM3 = new Manager(20, 500, 1),
  373. $lDM4 = new Manager(20, 500, 1),
  374. $lDM5 = new Manager(20, 500, 1),
  375. $lDM6 = new Manager(20, 500, 1),
  376. $lDM7 = new Manager(20, 500, 1),
  377. $lDM8 = new Manager(20, 500, 1),
  378. $lDM9 = new Manager(20, 500, 1),
  379. $lDM10 = new Manager(20, 500, 1),
  380. $lDM11 = new Manager(20, 500, 1),
  381. $lDM12 = new Manager(20, 500, 1),
  382. $lDM13 = new Manager(20, 500, 1),
  383. $lDM14 = new Manager(20, 500, 2),
  384. $lDM15 = new Manager(20, 500, 2),
  385. $lDM16 = new Manager(20, 500, 2),
  386. $lDM17 = new Manager(20, 500, 2),
  387. $lDM18 = new Manager(20, 500, 2),
  388. $lDEn1 = new Engeneer(5, 200, 1),
  389. $lDEn2 = new Engeneer(5, 200, 1),
  390. $lDEn3 = new Engeneer(5, 200, 1),
  391. $lDEn4 = new Engeneer(5, 200, 1),
  392. $lDEn5 = new Engeneer(5, 200, 1),
  393. ];
  394.  
  395. $purchaseDepartment = [$purhaseBoss, $purchaseDepartmentWorkers];
  396. $sellersDepartment = [$sellersBoss, $sellersDepartmentWorkers];
  397. $marketingDepartment = [$MarketingBoss, $marketingDepartmentWorkers];
  398. $logisticDepartment = [$logisticBoss, $logisticDepartmentWorkers];
  399.  
  400. $departments = [ "Purchase" => $purchaseDepartment,
  401. "Sellers" => $sellersDepartment,
  402. "Marketing" => $marketingDepartment,
  403. "Logistic" =>$logisticDepartment];
  404.  
  405. $col1 = 20;
  406. $col2 = 10;
  407. $col3 = 10;
  408. $col4 = 10;
  409. $col5 = 10;
  410. $col6 = 10;
  411.  
  412.  
  413. echo padRight("Department", $col1) .
  414. padLeft("Employees", $col2) .
  415. padLeft("Salary", $col3) .
  416. padLeft("Coffe", $col4) .
  417. padLeft("Pages", $col5) .
  418. padLeft("Page cost", $col6) . "\n";
  419.  
  420. echo str_repeat("_", 80) . "\n";
  421.  
  422. foreach($departments as $department){
  423. echo padRight(key($department), $col1) .
  424. padLeft(countAllWorkers($department), $col2) .
  425. padLeft(countAllSalary($department), $col3) .
  426. padLeft(departmentCoffeConsumption($department), $col4) .
  427. padLeft(allPages($department), $col5) .
  428. padLeft(pageCost($department), $col6) . "\n";
  429. }
  430.  
  431. echo str_repeat("_", 80) . "\n";
  432.  
  433. echo padRight("Total", $col1) .
  434. padLeft(totalEmployees($departments), $col2) .
  435. padLeft(totalSalary($departments), $col3) .
  436. padLeft(totalCoffe($departments), $col4) .
  437. padLeft(totalPages($departments), $col5) .
  438. padLeft(" ", $col6) . "\n";
  439.  
  440. echo str_repeat("_", 80) . "\n";
  441.  
  442. echo padRight("Avarage", $col1) .
  443. padLeft(avarageEmployees($departments), $col2) .
  444. padLeft(avarageSalary($departments), $col3) .
  445. padLeft(avarageCoffe($departments), $col4) .
  446. padLeft(avaragePages($departments), $col5) .
  447. padLeft(avaragePageCost($departments), $col6) . "\n";
  448.  
  449. /*
  450. foreach($departments as $department) {
  451.   echo str_repeat("_", 60) . "</br>";
  452.   echo "Boss Salary: " . $department[0]->getBossSalary() . "\n" .
  453.   "Boss coffe consumption " . $department[0]->getBossCoffeConsumption() . "\n" .
  454.   "Boss rank: " . $department[0]->rank . "</br>";
  455.   foreach ($department[1] as $worker) {
  456.   echo "Salary:" . $worker->getWorkerSalary() . "\n" .
  457.   "Coffe consumption: " . $worker->amountOfCoffe . "\n" .
  458.   "Rank: " . $worker->rank . "</br>";
  459.   }
  460.   echo str_repeat("_", 60) . "</br>";
  461.   }
  462. */
  463.  
  464. /*
  465. echo "Purchase Department" . "</br>";
  466. echo str_repeat("_", 60) . "</br>";
  467. echo "NumberOfWorkers: " . countAllWorkers($purchaseDepartment) . "</br>";
  468. echo "Total department salary: " . countAllSalary($purchaseDepartment) . "</br>";
  469. echo "Total department coffe consumption: " . departmentCoffeConsumption($purchaseDepartment) . "</br>";
  470. echo "Reports: " . countDepartmentReports($purchaseDepartment) . "</br>";
  471. echo "Main reports: " . countDepartmentMainReports($purchaseDepartment) . "</br>";
  472. echo "Blueprints: " . countDepartmentBlueprints($purchaseDepartment) . "</br>";
  473. echo "All pages: " . allPages($purchaseDepartment) . "</br>";
  474. echo "Cost of one page: " . pagesToMoneyRatio($purchaseDepartment) . "</br>";
  475. echo str_repeat("_", 60) . "</br>";
  476.  
  477.  
  478. echo "Sellers Department" . "</br>";
  479. echo str_repeat("_", 60) . "</br>";
  480. echo "NumberOfWorkers: " . countAllWorkers($sellersDepartment) . "</br>";
  481. echo "Total department salary: " . countAllSalary($sellersDepartment) . "</br>";
  482. echo "Total department coffe consumption: " . departmentCoffeConsumption($sellersDepartment) . "</br>";
  483. echo "Reports: " . countDepartmentReports($sellersDepartment) . "</br>";
  484. echo "Main reports: " . countDepartmentMainReports($sellersDepartment) . "</br>";
  485. echo "Blueprints: " . countDepartmentBlueprints($sellersDepartment) . "</br>";
  486. echo "All pages: " . allPages($sellersDepartment) . "</br>";
  487. echo "Cost of one page: " . pagesToMoneyRatio($sellersDepartment) . "</br>";
  488. echo str_repeat("_", 60) . "</br>";
  489.  
  490. echo "Marketing Department" . "</br>";
  491. echo str_repeat("_", 60) . "</br>";
  492. echo "NumberOfWorkers: " . countAllWorkers($marketingDepartment) . "</br>";
  493. echo "Total department salary: " . countAllSalary($marketingDepartment) . "</br>";
  494. echo "Total department coffe consumption: " . departmentCoffeConsumption($marketingDepartment) . "</br>";
  495. echo "Reports: " . countDepartmentReports($marketingDepartment) . "</br>";
  496. echo "Main reports: " . countDepartmentMainReports($marketingDepartment) . "</br>";
  497. echo "Blueprints: " . countDepartmentBlueprints($marketingDepartment) . "</br>";
  498. echo "All pages: " . allPages($marketingDepartment) . "</br>";
  499. echo "Cost of one page: " . pagesToMoneyRatio($marketingDepartment) . "</br>";
  500. echo str_repeat("_", 60) . "</br>";
  501.  
  502. echo "Logistic Department" . "</br>";
  503. echo str_repeat("_", 60) . "</br>";
  504. echo "NumberOfWorkers: " . countAllWorkers($logisticDepartment) . "</br>";
  505. echo "Total department salary: " . countAllSalary($logisticDepartment) . "</br>";
  506. echo "Total department coffe consumption: " . departmentCoffeConsumption($logisticDepartment) . "</br>";
  507. echo "Reports: " . countDepartmentReports($logisticDepartment) . "</br>";
  508. echo "Main reports: " . countDepartmentMainReports($logisticDepartment) . "</br>";
  509. echo "Blueprints: " . countDepartmentBlueprints($logisticDepartment) . "</br>";
  510. echo "All pages: " . allPages($logisticDepartment) . "</br>";
  511. echo "Cost of one page: " . pagesToMoneyRatio($logisticDepartment) . "</br>";
  512. echo str_repeat("_", 60) . "</br>";
  513.  
  514. echo "Total employees: " . totalEmployees($departments) . "</br>";
  515. echo "Total Salary: " . totalSalary($departments) . "</br>";
  516. echo "Total Coffe: " . totalCoffe($departments) . "</br>";
  517. echo "Total Pages: " . totalPages($departments) . "</br>";
  518. echo "Total cost of one page: " . totalMonyPagesRation($departments) . "</br>";
  519. echo str_repeat("_", 60) . "</br>";
  520.  
  521. echo "Avarage employees: " . AvarageEmployees($departments) . "</br>";
  522. echo "Avarage salary: " . avarageSalary($departments) . "</br>";
  523. echo "Avarage coffe: " . avarageCoffe($departments) . "</br>";
  524. echo "Avarage pages: " . avaragePages($departments) . "</br>";
  525. echo "Avarage page cost: " . avaragePageCost($departments) . "</br>";
  526.  */
  527.  
Success #stdin #stdout 0.03s 23924KB
stdin
Standard input is empty
stdout
Department           Employees    Salary     Coffe     Pages Page cost
________________________________________________________________________________
0                           17    9612.5       350      3100       3.1
0                           24   13737.5       620      3325      4.13
0                           36     16525       585      5450      3.03
0                           24     11375       420      3850      2.95
________________________________________________________________________________
Total                      101     51250      1975     15725          
________________________________________________________________________________
Avarage                     25   12812.5     493.8      3931      3.26