fork 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. for($i = 0; $i < $length - $cl; $i++){
  116. $text = " ".$text;
  117. }}
  118. return $text;
  119. }
  120. function padRight($text, $length){
  121. $cl = mb_strlen($text);
  122. if($cl<$length){
  123. for($i = 0; $i < $length - $cl; $i++){
  124. $text = $text." ";
  125. }}
  126. return $text;
  127. }
  128.  
  129. $col1 = 10;
  130. $col2 = 5;
  131. $col3 = 5;
  132. $col4 = 5;
  133. $col5 = 5;
  134. $col6 = 5;
  135.  
  136. $col1 = 11;
  137. $col2 = 11;
  138. $col3 = 11;
  139. $col4 = 11;
  140. $col5 = 11;
  141. $col6 = 13;
  142.  
  143. $buyers = new Department;
  144. $buyers->name = "Закупок";
  145. $buyers->addEmployees(9, new Manager(1));
  146. $buyers->addEmployees(3, new Manager(2));
  147. $buyers->addEmployees(2, new Marketer(1));
  148. $buyers->addLeader(new Manager(2));
  149.  
  150. $sellers = new Department;
  151. $sellers->name = "Продаж";
  152. $sellers->addEmployees(12, new Manager(1));
  153. $sellers->addEmployees(6, new Marketer(1));
  154. $sellers->addEmployees(3, new Analytics(1));
  155. $sellers->addEmployees(2, new Analytics(2));
  156. $sellers->addLeader(new Marketer(2));
  157.  
  158. $advertisers->name = "Рекламы";
  159. $advertisers->addEmployees(15, new Marketer(1));
  160. $advertisers->addEmployees(10, new Marketer(2));
  161. $advertisers->addEmployees(8, new Manager(1));
  162. $advertisers->addEmployees(2, new Engineer(1));
  163. $advertisers->addLeader(new Manager(1));
  164.  
  165. $logistics = new Department;
  166. $logistics->name = "Логистики";
  167. $logistics->addEmployees(13, new Manager(1));
  168. $logistics->addEmployees(5, new Manager(2));
  169. $logistics->addEmployees(5, new Engineer(1));
  170. $logistics->addLeader(new Manager(1));
  171.  
  172. $departments = array($buyers, $sellers, $advertisers, $logistics);
  173. echo (padRight("Департамент",$col1).
  174. padLeft("сотр.",$col2).
  175. padLeft("тугр.",$col3).
  176. padLeft("кофе",$col4).
  177. padLeft("стр.",$col5).
  178. padLeft("тугр./стр.",$col6)."\n---------------------------------------------------------------------------\n");
  179.  
  180. foreach ($departments as $department){
  181. echo padRight($department->name,$col1).
  182. padLeft($department->getTotalEmployees(),$col2).
  183. padLeft($department->getTotalIncome(),$col3).
  184. padLeft($department->getTotalCoffee(),$col4).
  185. padLeft($department->getTotalPapers(),$col5).
  186. padLeft(floor($department->getTotalIncome()/$department->getTotalPapers()),$col6)."\n";}
  187.  
  188.  
Runtime error #stdin #stdout #stderr 0.02s 24400KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Warning:  Creating default object from empty value in /home/XxFtIK/prog.php on line 159
PHP Fatal error:  Call to undefined method stdClass::addEmployees() in /home/XxFtIK/prog.php on line 160