fork download
  1. <?php
  2. abstract class Employee {
  3. public function __construct($rang = 1, $leader = false) {
  4. $this->rang = $rang;
  5. $this->leader = $leader;
  6.  
  7. $this->newSolary = $this->calculateSolary();
  8. $this->newCoffe = $this->calculateCoffe();
  9. $this->newDocument = $this->calculateDocument();
  10. }
  11.  
  12. public function calculateSolary() {
  13. switch ($this->rang) {
  14. case 1:
  15. $this->newSolary = $this->solary;
  16. break;
  17.  
  18. case 2:
  19. $this->newSolary = $this->solary + ($this->solary * 0.25);
  20. break;
  21.  
  22. case 3:
  23. $this->newSolary = $this->solary + ($this->solary * 0.50);
  24. break;
  25. }
  26.  
  27. if ($leader) {
  28. $this->newSolary = $this->newSolary + ($this->newSolary * 0.50);
  29. }
  30.  
  31. return $this->newSolary; /* Не уверен в необхадимости этой строки, ведь это свойство и так изменяется само по себе. По сему назривают следующие вопросы:
  32. 1. Необхадимо ли передача этого параметра?
  33. 2. Будет ли правильнее создание заместо этого параметра создать обычную переменную внутри функции и далее, её уже передавать?
  34. */
  35. }
  36.  
  37. public function calculateCoffe() {
  38. if ($leader) {
  39. $this->newCoffe = $this->coffe * 2;
  40. }
  41.  
  42. return $this->newCoffe;
  43. }
  44.  
  45. public function calculateDocument() {
  46. if ($leader) {
  47. $this->newDocument = 0;
  48. }
  49.  
  50. return $this->newDocument;
  51. }
  52. }
  53.  
  54.  
  55. class Manager extends Employee {
  56. public $rang;
  57.  
  58. public $solary = 500;
  59. public $newSolary;
  60.  
  61. public $coffe = 20;
  62. public $newCoffe;
  63.  
  64. public $document = 200;
  65. public $newDocument;
  66.  
  67. public $leader;
  68. }
  69.  
  70. class Marketer extends Employee {
  71. public $rang;
  72.  
  73. public $solary = 400;
  74. public $newSolary;
  75.  
  76. public $coffe = 15;
  77. public $newCoffe;
  78.  
  79. public $document = 150;
  80. public $newDocument;
  81.  
  82. public $leader;
  83. }
  84.  
  85. class Engineer extends Employee {
  86. public $rang;
  87.  
  88. public $solary = 200;
  89. public $newSolary;
  90.  
  91. public $coffe = 5;
  92. public $newCoffe;
  93.  
  94. public $document = 50;
  95. public $newDocument;
  96.  
  97. public $leader;
  98. }
  99.  
  100. class Analyst extends Employee {
  101. public $rang;
  102.  
  103. public $solary = 800;
  104. public $newSolary;
  105.  
  106. public $coffe = 50;
  107. public $newCoffe;
  108.  
  109. public $document = 5;
  110. public $newDocument;
  111.  
  112. public $leader;
  113. }
  114.  
  115. abstract class Department {
  116.  
  117. public function __construct() {
  118. $this->addManagersToDepartment();
  119. $this->addMarketersToDepartment();
  120. $this->addEngineersToDepartment();
  121. $this->addAnalystsToDepartment();
  122. $this->addLeaderToDepartment();
  123.  
  124. $this->calculateEmployeesNumberInDepartment();
  125. $this->calculateDepartmentExpensesCoffeAndDocuemnt();
  126. $this->calculateAvargeValue();
  127. }
  128.  
  129. //Здесь смею допусть повторение однотипного кода потому что иначе было бы еще более "муторно", хоть я сам не одобряю такой подход, но тем не мение это всего лишь задачка.
  130. public function addManagersToDepartment() {
  131. foreach ($this->managerNumber as $key => $value) {
  132. for ($i = 1; $i = $this->managerNumber[$value]; i++) {
  133. $this->employees[$this->nameOfDepartment]['Managers'][$i] = new Manager($key);
  134. }
  135. }
  136. }
  137.  
  138. public function addMarketersToDepartment() {
  139. foreach ($this->marketersNumber as $key => $value) {
  140. for ($i = 1; $i = $this->marketersNumber[$value]; i++) {
  141. $this->employees[$this->nameOfDepartment]['Marketers'][$i] = new Marketer($key);
  142. }
  143. }
  144. }
  145.  
  146. public function addEngineersToDepartment() {
  147. foreach ($this->engineerNumber as $key => $value) {
  148. for ($i = 1; $i = $this->engineerNumber[$value]; i++) {
  149. $this->employees[$this->nameOfDepartment]['Engineers'][$i] = new Engineer($key);
  150. }
  151. }
  152. }
  153.  
  154. public function addAnalystsToDepartment() {
  155. foreach ($this->analystNumber as $key => $value) {
  156. for ($i = 1; $i = $this->analystNumber[$value]; i++) {
  157. $this->employees[$this->nameOfDepartment]['Analysts'][$i] = new Analyst($key);
  158. }
  159. }
  160. }
  161.  
  162. public function addLeaderToDepartment() {
  163. switch ($this->departmentLeader["type"]) {
  164. case 'manager':
  165. $this->employees[$this->nameOfDepartment]['Leader'][] = new Manager($this->departmentLeader["rang"], true);
  166. break;
  167.  
  168. case 'marketer':
  169. $this->employees[$this->nameOfDepartment]['Leader'][] = new Marketer($this->departmentLeader["rang"], true);
  170. break;
  171.  
  172. case 'engineer':
  173. $this->employees[$this->nameOfDepartment]['Leader'][] = new Engineer($this->departmentLeader["rang"], true);
  174. break;
  175.  
  176. case 'analyst':
  177. $this->employees[$this->nameOfDepartment]['Leader'][] = new Analyst($this->departmentLeader["rang"], true);
  178. break;
  179. }
  180. }
  181.  
  182. public function calculateEmployeesNumberInDepartment() {
  183. $calculateManagersNumber = count($this->employees[$this->nameOfDepartment]['Managers']);
  184. $calculateMarketersNumber = count($this->employees[$this->nameOfDepartment]['Marketers']);
  185. $calculateEngineersNumber = count($this->employees[$this->nameOfDepartment]['Engineers']);
  186. $calculateAnalystsNumber = count($this->employees[$this->nameOfDepartment]['Analysts']);
  187. $oneLeader = count($this->employees[$this->nameOfDepartment]['Leader']);
  188.  
  189. $this->$employeesNumber = $calculateManagersNumber + $calculateMarketersNumber + $calculateEngineersNumber + $calculateAnalystsNumber + $oneLeader;
  190.  
  191. return $this->$employeesNumber;
  192. }
  193.  
  194. public function calculateDepartmentExpensesCoffeAndDocuemnt() {
  195. foreach ($this->employees[$this->nameOfDepartment]['Managers'] as $key => $value) {
  196. $calculateManagersExpenses += $value->newSolary;
  197. $calculateManagersCoffe += $value->newCoffe;
  198. $calculateManagersDocument += $value->newDocument;
  199. }
  200.  
  201. foreach ($this->employees[$this->nameOfDepartment]['Marketers'] as $key => $value) {
  202. $calculateMarketersExpenses += $value->newSolary;
  203. $calculateMarketersCoffe += $value->newCoffe;
  204. $calculateMarketersDocument += $value->newDocument;
  205. }
  206.  
  207. foreach ($this->employees[$this->nameOfDepartment]['Engineers'] as $key => $value) {
  208. $calculateEngineersExpenses += $value->newSolary;
  209. $calculateEngineersCoffe += $value->newCoffe;
  210. $calculateEngineersDocument += $value->newDocument;
  211. }
  212.  
  213. foreach ($this->employees[$this->nameOfDepartment]['Analysts'] as $key => $value) {
  214. $calculateAnalystsExpenses += $value->newSolary;
  215. $calculateAnalystsCoffe += $value->newCoffe;
  216. $calculateAnalystsDocument += $value->newDocument;
  217. }
  218.  
  219. foreach ($this->employees[$this->nameOfDepartment]['Leader'] as $key => $value) {
  220. $calculateLeaderExpenses = $value->newSolary;
  221. $calculateLeaderCoffe += $value->newCoffe;
  222. $calculateLeaderDocuments += $value->newDocument;
  223. }
  224.  
  225. $calculateDepartmentExpenses = $calculateManagersExpenses + $calculateMarketersExpenses + $calculateEngineersExpenses + $calculateAnalystsExpenses + $calculateLeaderExpenses;
  226. $calculateDepartmentCoffe = $calculateManagersCoffe + $calculateMarketersCoffe + $calculateEngineersCoffe + $calculateAnalystsCoffe + $calculateLeaderCoffe;
  227. $calculateDepartmentDocuments = $calculateManagersDocuments + $calculateMarketersDocuments + $calculateEngineersDocuments + $calculateAnalystsDocuments + $calculateLeaderDocuments;
  228.  
  229. $this->expenses = array($calculateDepartmentExpenses, $calculateDepartmentCoffe, $calculateDepartmentDocuments);
  230.  
  231. return $this->expenses;
  232. }
  233.  
  234. public function calculateAvargeValue() {
  235. $this->avargeValue = $this->expenses[0] / $this->expenses[2];
  236. }
  237. }
  238.  
  239. class Procurement extends Department {
  240. public $nameOfDepartment = 'Procurement';
  241.  
  242. public $employees = array();
  243.  
  244. public $managerNumber = array(1 => 9, 2 => 3, 3 => 2);
  245. public $marketerNumber = array(1 => 2, 2 => 0, 3 => 0);
  246. public $engineerNumber = array(1 => 0, 2 => 0, 3 => 0);
  247. public $analystNumber = array(1 => 0, 2 => 0, 3 => 0);
  248. public $departmentLeader = array("rang" => 2, "type" => 'manager');
  249.  
  250. public $employeesNumber;
  251.  
  252. public $expenses = array();
  253. public $avargeValue;
  254. }
  255.  
  256. class Sales extends Department {
  257. public $nameOfDepartment = 'Sales';
  258.  
  259. public $employees = array();
  260.  
  261. public $managerNumber = array(1 => 12, 2 => 0, 3 => 0);
  262. public $marketerNumber = array(1 => 6, 2 => 0, 3 => 0);
  263. public $engineerNumber = array(1 => 0, 2 => 0, 3 => 0);
  264. public $analystNumber = array(1 => 3, 2 => 2, 3 => 0);
  265. public $departmentLeader = array("rang" => 2, "type" => 'marketer');
  266.  
  267. public $employeesNumber;
  268.  
  269. public $expenses = array();
  270. public $avargeValue;
  271. }
  272.  
  273. class Advertising extends Department {
  274. public $nameOfDepartment = 'Sales';
  275.  
  276. public $employees = array();
  277.  
  278. public $managerNumber = array(1 => 8, 2 => 0, 3 => 0);
  279. public $marketerNumber = array(1 => 15, 2 => 10, 3 => 0);
  280. public $engineerNumber = array(1 => 2, 2 => 0, 3 => 0);
  281. public $analystNumber = array(1 => 0, 2 => 0, 3 => 0);
  282. public $departmentLeader = array("rang" => 3, "type" => 'marketer');
  283.  
  284. public $employeesNumber;
  285.  
  286. public $expenses = array();
  287. public $avargeValue;
  288. }
  289.  
  290. class Logistics extends Department {
  291. public $nameOfDepartment = 'Sales';
  292.  
  293. public $employees = array();
  294.  
  295. public $managerNumber = array(1 => 13, 2 => 5, 3 => 0);
  296. public $marketerNumber = array(1 => 0, 2 => 0, 3 => 0);
  297. public $engineerNumber = array(1 => 5, 2 => 0, 3 => 0);
  298. public $analystNumber = array(1 => 0, 2 => 0, 3 => 0);
  299. public $departmentLeader = array("rang" => 1, "type" => 'manager');
  300.  
  301. public $employeesNumber;
  302.  
  303. public $expenses = array();
  304. public $avargeValue;
  305. }
Runtime error #stdin #stdout #stderr 0.02s 24400KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Parse error:  syntax error, unexpected '++' (T_INC), expecting ')' in /home/55JTIh/prog.php on line 132