fork(1) download
  1. <?php
  2. class Department
  3. {
  4. public $name;
  5. public $employees = array();
  6.  
  7. public function addEmployees($quantity, $employee)
  8. {
  9. for($i = 0; $i < $quantity; $i++){
  10. array_push($this->employees, clone $employee);
  11. }
  12. return $this->employees;
  13. }
  14.  
  15. public function addLeader($employee){
  16. $employee->setRank();
  17. $employee->makeLeader();
  18. array_push($this->employees,$employee);
  19. return $this;
  20. }
  21.  
  22. public function getTotalEmployees()
  23. { $total = 0;
  24. foreach ($this->employees as $employee){
  25. $total++;
  26. }
  27. return $total;
  28. }
  29.  
  30. public function getTotalCoffee(){
  31. $total = 0;
  32. foreach ($this->employees as $employee) {
  33. $total+=$employee->coffee;
  34. }
  35. return $total;
  36. }
  37.  
  38. public function getTotalPapers(){
  39. $total = 0;
  40. foreach ($this->employees as $employee) {
  41. $total+=$employee->papers;
  42. }
  43. return $total;
  44. }
  45.  
  46. public function getTotalIncome(){
  47. $total = 0;
  48. foreach ($this->employees as $employee) {
  49. $total += $employee->income;
  50. }
  51. return floor($total);
  52. }
  53.  
  54.  
  55. }
  56.  
  57. abstract class Employee
  58. {
  59. public $rank;
  60. public $income;
  61. public $coffee;
  62. public $papers;
  63. public function __construct($rank)
  64. {
  65. $this->rank = $rank;
  66. }
  67.  
  68. public function setRank()
  69. {
  70. $rank = $this->rank;
  71. if($rank == 2){
  72. $this->income *= 1.25;
  73. }
  74. elseif($rank == 3){
  75. $this->income *= 1.5;
  76. }
  77. return $this;
  78. }
  79. public function makeLeader(){
  80. $this->income *= 1.5;
  81. $this->coffee *= 2;
  82. $this->papers = 0;
  83. return $this;
  84. }
  85. }
  86.  
  87. class Manager extends Employee
  88. {
  89. public $income = 500;
  90. public $coffee = 20;
  91. public $papers = 200;
  92. }
  93. class Marketer extends Employee
  94. {
  95. public $income = 400;
  96. public $coffee = 15;
  97. public $papers = 150;
  98. }
  99. class Engineer extends Employee
  100. {
  101. public $income = 200;
  102. public $coffee = 5;
  103. public $papers = 50;
  104. }
  105. class Analytics extends Employee
  106. {
  107. public $income = 800;
  108. public $coffee = 50;
  109. public $papers = 5;
  110. }
  111.  
  112. function padLeft($text, $length){
  113. $cl = mb_strlen($text);
  114. if($cl<$length){
  115. $text =str_repeat(" ", $length - $cl).$text;
  116. }
  117. return $text;
  118. }
  119. function padRight($text, $length){
  120. $cl = mb_strlen($text);
  121. if($cl<$length){
  122. $text = $text.str_repeat(" ", $length - $cl);
  123. }
  124. return $text;
  125. }
  126.  
  127.  
  128.  
  129. $manager = new Manager(2); // создаем менеджера 2 ранга
  130. // пытаемся узнать его зарплату
  131. var_dump($manager->income);
  132.  
  133. $manager->setRank();
  134. $manager->setRank();
  135. $manager->setRank();
  136. $manager->setRank();
  137. $manager->setRank();
  138. $manager->setRank();
  139.  
  140.  
  141. // пытаемся еще раз узнать его зарплату
  142. var_dump($manager->income);
  143.  
  144.  
  145.  
  146. // $col1 = 11;
  147. // $col2 = 11;
  148. // $col3 = 11;
  149. // $col4 = 11;
  150. // $col5 = 11;
  151. // $col6 = 13;
  152. // $col7 = 11;
  153.  
  154. // $buyers = new Department;
  155. // $buyers->name = "Закупок";
  156. // $buyers->addEmployees(9, new Manager(1));
  157. // $buyers->addEmployees(3, new Manager(2));
  158. // $buyers->addEmployees(2, new Marketer(1));
  159. // $buyers->addLeader(new Manager(2));
  160.  
  161. // $sellers = new Department;
  162. // $sellers->name = "Продаж";
  163. // $sellers->addEmployees(12, new Manager(1));
  164. // $sellers->addEmployees(6, new Marketer(1));
  165. // $sellers->addEmployees(3, new Analytics(1));
  166. // $sellers->addEmployees(2, new Analytics(2));
  167. // $sellers->addLeader(new Marketer(2));
  168.  
  169. // $advertisers = new Department;
  170. // $advertisers->name = "Рекламы";
  171. // $advertisers->addEmployees(15, new Marketer(1));
  172. // $advertisers->addEmployees(10, new Marketer(2));
  173. // $advertisers->addEmployees(8, new Manager(1));
  174. // $advertisers->addEmployees(2, new Engineer(1));
  175. // $advertisers->addLeader(new Manager(1));
  176.  
  177. // $logistics = new Department;
  178. // $logistics->name = "Логистики";
  179. // $logistics->addEmployees(13, new Manager(1));
  180. // $logistics->addEmployees(5, new Manager(2));
  181. // $logistics->addEmployees(5, new Engineer(1));
  182. // $logistics->addLeader(new Manager(1));
  183.  
  184. // $departments = array($buyers, $sellers, $advertisers, $logistics);
  185.  
  186. // foreach ($departments as $department) {
  187. // $totalEmp+=$department->getTotalEmployees();
  188. // $totalInc+=$department->getTotalIncome();
  189. // $totalCof+=$department->getTotalCoffee();
  190. // $totalPap+=$department->getTotalPapers();
  191. // $totalPrice+=floor($department->getTotalIncome()/$department->getTotalPapers());
  192. // }
  193.  
  194. // $avIncome = floor($totalInc/count($departments));
  195. // $avEmp = floor($totalEmp / count($departments));
  196. // $avCof = floor($totalCof / count($departments));
  197. // $avPap = floor($totalPap / count($departments));
  198. // $avPrice = floor($totalPrice / count($departments));
  199.  
  200. // echo (padRight("Департамент",$col1).
  201. // padLeft("сотр.",$col2).
  202. // padLeft("тугр.",$col3).
  203. // padLeft("кофе",$col4).
  204. // padLeft("стр.",$col5).
  205. // padLeft("тугр./стр.",$col6)."\n---------------------------------------------------------------------------\n");
  206.  
  207.  
  208.  
  209. // foreach ($departments as $department){
  210. // echo padRight($department->name,$col1).
  211. // padLeft($department->getTotalEmployees(),$col2).
  212. // padLeft($department->getTotalIncome(),$col3).
  213. // padLeft($department->getTotalCoffee(),$col4).
  214. // padLeft($department->getTotalPapers(),$col5).
  215. // padLeft(floor($department->getTotalIncome()/$department->getTotalPapers()),$col6)."\n";
  216. // }
  217.  
  218.  
  219. // echo (
  220. // padRight("Среднее", $col1).
  221. // padLeft($avEmp, $col2).
  222. // padLeft($avIncome, $col3).
  223. // padLeft($avCof, $col4).
  224. // padLeft($avPap, $col5).
  225. // padLeft($avPrice, $col6)."\n"
  226. // );
  227.  
  228. // echo(
  229. // padRight("Всего",$col1).
  230. // padLeft($totalEmp, $col2).
  231. // padLeft($totalInc, $col3).
  232. // padLeft($totalCof, $col4).
  233. // padLeft($totalPap, $col5).
  234. // padLeft($totalPrice, $col6)
  235.  
  236.  
  237. // );
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
int(500)
float(1907.3486328125)