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