fork download
  1. <?php
  2.  
  3.  
  4. abstract class Worker {
  5. public $name;
  6. public $level;
  7. public $chief;
  8. public $coffe;
  9. public $paid;
  10. public $pages;
  11.  
  12. public function drinkCoffe() {
  13. if ($this->chief) {
  14. return ($this->coffe *2);
  15. } else {
  16. return $this->coffe;
  17. }
  18. }
  19. public function getPaid() {
  20. if ($this->level == 3) { $cof = 1.5; } elseif ($this->level == 2) { $cof = 1.25; } elseif ($this->level == 1) { $cof = 1;} else { echo "Invalid level\n"; die;}
  21. if ($this->chief) {
  22. $paid = $this->paid * 2 * $cof;
  23. return $paid;
  24. } else {
  25. $paid = $this->paid * $cof;
  26. return $paid;
  27. }
  28. }
  29. public function getUseCof() { // Получаем отношения деньги/страницы
  30. if ($this->pages == 0) {
  31. return $this->getPaid();
  32. } else {
  33. $rate = $this->getPaid() / $this-> pages;
  34. return $rate;
  35. }
  36. }
  37. }
  38. class Manager extends Worker {
  39. public function __construct($name, $level, $chief) {
  40. $this->name = $name;
  41. $this->level = $level;
  42. $this->chief = $chief;
  43. $this->coffe = 20;
  44. $this->paid = 500;
  45. $this->paid = $this->getPaid();
  46. if ($this->chief) {
  47. $this->pages = 0;
  48. } else {
  49. $this->pages = 200;
  50. }
  51. }
  52. }
  53. class Engeneer extends Worker {
  54. public function __construct($name, $level, $chief) {
  55. $this->name = $name;
  56. $this->level = $level;
  57. $this->chief = $chief;
  58. $this->coffe = 5;
  59. $this->paid = 200;
  60. $this->paid = $this->getPaid();
  61. if ($this->chief) {
  62. $this->pages = 0;
  63. } else {
  64. $this->pages = 50;
  65. }
  66. }
  67. }
  68. class Marketing extends Worker {
  69. public function __construct($name, $level, $chief) {
  70. $this->name = $name;
  71. $this->level = $level;
  72. $this->chief = $chief;
  73. $this->coffe = 15;
  74. $this->paid = 400;
  75. $this->paid = $this->getPaid();
  76. if ($this->chief) {
  77. $this->pages = 0;
  78. } else {
  79. $this->pages = 150;
  80. }
  81. }
  82. }
  83. class Analyst extends Worker {
  84. public function __construct($name, $level, $chief) {
  85. $this->name = $name;
  86. $this->level = $level;
  87. $this->chief = $chief;
  88. $this->coffe = 50;
  89. $this->paid = 800;
  90. $this->paid = $this->getPaid();
  91. if ($this->chief) {
  92. $this->pages = 0;
  93. } else {
  94. $this->pages = 5;
  95. }
  96. }
  97. }
  98. function rightPad($string, $symbols) {
  99. $len = mb_strlen($string);
  100. if ($len < $symbols) {
  101. $add = $symbols - $len;
  102. return ($string.str_pad("", $add));
  103. } else {
  104. return $string;
  105. }
  106. }
  107. function leftPad($string, $symbols) {
  108. $len = mb_strlen($string);
  109. if ($len < $symbols) {
  110. $add = $symbols - $len;
  111. return (str_pad("", $add).$string);
  112. } else {
  113. return $string;
  114. }
  115. }
  116. class Departament {
  117. public $name;
  118. public $workers;
  119.  
  120. public function __construct($name){
  121. $this->name = $name;
  122. $this->workers = array();
  123. }
  124. public function addWorkers($example, $count) {
  125. $array_count = count($this->workers);
  126. for ($i = $array_count; $i <= ($array_count + $count); $i++) {
  127. $this->workers[] = $example;
  128. }
  129. }
  130. public function totalySalary() {
  131. $total = 0;
  132. foreach ($this->workers as $key => $value) {
  133. $total += $this->workers[$key]->paid;
  134. }
  135. return $total;
  136. }
  137. public function totalyCoffe() {
  138. $totalyCoffe = 0;
  139. foreach ($this->workers as $key => $value) {
  140. $totalyCoffe += $this->workers[$key]->coffe;
  141. }
  142. return $totalyCoffe;
  143. }
  144. public function totalyPages() {
  145. $totalyPages = 0;
  146. foreach ($this->workers as $key => $value) {
  147. $totalyPages += $this->workers[$key]->pages;
  148. }
  149. return $totalyPages;
  150. }
  151. public function averagePrice() {
  152. $price = 0;
  153. foreach ($this->workers as $key => $value) {
  154. $price += $this->workers[$key]->getUseCof();
  155. }
  156. return $price/count($this->workers);
  157. }
  158. }
  159.  
  160. $manager1L = new Manager('Петров И.', 1, False);
  161. $manager2L = new Manager('Иванов П.', 2, False);
  162. $manager3L = new Manager('Рустамович Ш.', 3, False);
  163. $chiefMa2 = new Manager("Шеф", 2, True);
  164. $chiefMarket2 = new Marketing("Шеф", 2, True);
  165. $marketing1L = new Marketing('Шухратович Р', 3, False);
  166. $analyst1L = new Analyst('Доброевский Р.', 3, False);
  167. $analyst2L = new Analyst('Вербицкий М.', 2, False);
  168.  
  169. $buying = new Departament('Закупок');
  170. $buying->addWorkers($manager1L, 9);
  171. $buying->addWorkers($manager2L, 3);
  172. $buying->addWorkers($manager3L, 2);
  173. $buying->addWorkers($marketing1L, 1);
  174. $buying->addWorkers($chiefMa2, 1);
  175.  
  176. $selling = new Departament('Продаж');
  177. $selling->addWorkers($manager1L, 12);
  178. $selling->addWorkers($marketing1L, 6);
  179. $selling->addWorkers($analyst1L, 3);
  180. $selling->addWorkers($analyst2L, 2);
  181. $selling->addWorkers($chiefMarket2, 1);
  182.  
  183. $departaments = array();
  184. $departaments[] = $buying;
  185. $departaments[] = $selling;
  186.  
  187. $col = 20;
  188. $table = array ('Департамент', 'Сотрудников', 'Тугр.', 'Кофе', 'Стр', 'Т/СТР');
  189. foreach ($table as $key => $value) {
  190. echo rightPad($table[$key], $col);
  191. }
  192. echo "\n";
  193.  
  194. foreach ($departaments as $key => $value) {
  195. echo rightPad($departaments[$key]->name, $col);
  196. echo rightPad(count($departaments[$key]->workers), $col);
  197. echo rightPad($departaments[$key]->totalySalary(), $col);
  198. echo rightPad($departaments[$key]->totalyCoffe(), $col);
  199. echo rightPad($departaments[$key]->totalyPages(), $col);
  200. echo rightPad(ceil($departaments[$key]->averagePrice()), $col);
  201. echo "\n";
  202. }
  203. ?>
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Департамент         Сотрудников         Тугр.               Кофе                Стр                 Т/СТР               
Закупок             21                  13450               410                 3700                301                 
Продаж              29                  20500               745                 3685                251