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