fork download
  1. <?php
  2.  
  3. class Organisation //содержит методы для подсчета общих и средних параметров по конторе
  4. {
  5. public $name;
  6. public $departments = [];
  7.  
  8. public function __construct($name)
  9. {
  10. $this->name = $name;
  11. }
  12.  
  13. public function countTotalWorkers()
  14. {
  15. $totalWorkers = 0;
  16. foreach($this->departments as $unit) {
  17. $totalWorkers += $unit->countDepWorkers();
  18. }
  19. return $totalWorkers;
  20. }
  21.  
  22. public function countAveregeWorkers()
  23. {
  24. return $this->countTotalWorkers() / count($this->departments);
  25. }
  26.  
  27. public function countTotalStuff($stuff)
  28. {
  29. $companyStuff = 0;
  30. foreach ($this->departments as $dep) {
  31. $companyStuff += $dep->countDepStuff($stuff);
  32. }
  33. return $companyStuff;
  34. }
  35.  
  36. public function countAveregeStuff($stuff)
  37. {
  38. return $this->countTotalStuff($stuff) / count($this->departments);
  39. }
  40.  
  41. public function countTotalEfficiency()
  42. {
  43. $companyEfficiency = 0;
  44. foreach ($this->departments as $dep) {
  45. $companyEfficiency += $dep->countDepEfficiency();
  46. }
  47. return $companyEfficiency;
  48. }
  49.  
  50. public function countAveregeEfficiency()
  51. {
  52. return $this->countTotalEfficiency() / count($this->departments);
  53. }
  54.  
  55. }
  56.  
  57. class Department
  58. {
  59. public $name;
  60. public $workers = [];
  61.  
  62. public function __construct($name)
  63. {
  64. $this->name = $name;
  65. }
  66.  
  67. public function addWorkers($amount, $class, $rank, $leader) {
  68. for($i=1; $i<=$amount; $i++ ) {
  69. $this->workers[] = new $class($rank, $leader);
  70. }
  71. }
  72.  
  73. public function getName()
  74. {
  75. return $this->name;
  76. }
  77.  
  78. public function countDepWorkers()
  79. {
  80. return count($this->workers);
  81. }
  82.  
  83. public function countDepStuff($stuff)
  84. {
  85. $totalDepStuff = 0;
  86. foreach ($this->workers as $worker) {
  87. $totalDepStuff += $worker->$stuff;
  88. }
  89. return $totalDepStuff;
  90. }
  91.  
  92. function countDepEfficiency()
  93. {
  94. return $this->countDepStuff("salary") / $this->countDepStuff("docs");
  95. }
  96.  
  97. }
  98.  
  99. class Employee
  100. {
  101. public $salary;
  102. public $coffeUsage;
  103. public $docs;
  104. public $rank;
  105. public $leader;
  106. public $defaultSalary;
  107.  
  108. public function __construct($rank, $leader) {
  109. $this->rank = $rank;
  110. $this->leader = $leader;
  111. $this->setSalary();
  112. $this->setCoffeUsage();
  113. $this->setDocs();
  114. }
  115.  
  116. public function setSalary ()
  117. {
  118. if ($this->rank == 2) {
  119. $rankBonus = 1.25;
  120. } elseif ($this->rank == 3) {
  121. $rankBonus = 1.5;
  122. } else {
  123. $rankBonus = 1;
  124. }
  125.  
  126. if ($this->leader == true) {
  127. $leaderBonus = 1.5;
  128. } else {
  129. $leaderBonus = 1;
  130. }
  131. $this->salary = $this->defaultSalary * $rankBonus * $leaderBonus;
  132. }
  133.  
  134. public function setCoffeUsage()
  135. {
  136. if ($this->leader) {
  137. $this->coffeUsage = $this->defaultCoffeUsage * 2;
  138. } else {
  139. $this->coffeUsage = $this->defaultCoffeUsage;
  140. }
  141. }
  142.  
  143. public function setDocs ()
  144. {
  145. if ($this->leader) {
  146. $this->docs = 0;
  147. } else {
  148. $this->docs = $this->defaultDocs;
  149. }
  150. }
  151. }
  152.  
  153. class Manager extends Employee
  154. {
  155. public $defaultSalary = 500;
  156. public $defaultCoffeUsage = 20;
  157. public $defaultDocs = 200;
  158. }
  159.  
  160. class MarketGuy extends Employee
  161. {
  162. public $defaultSalary = 400;
  163. public $defaultCoffeUsage = 15;
  164. public $defaultDocs = 150;
  165. }
  166.  
  167. class Engineer extends Employee
  168. {
  169. public $defaultSalary = 200;
  170. public $defaultCoffeUsage = 5;
  171. public $defaultDocs = 50;
  172. }
  173.  
  174. class Analyst extends Employee
  175. {
  176. public $defaultSalary = 800;
  177. public $defaultCoffeUsage = 50;
  178. public $defaultDocs = 5;
  179. }
  180.  
  181.  
  182.  
  183. function padLeft ($string, $length) {
  184. $strLength = mb_strlen($string);
  185. $spases = str_repeat(" ", ($length - $strLength - 1));
  186. $string = "|" . $spases . $string;
  187. return $string;
  188. }
  189.  
  190. function padRight ($string, $length) {
  191. $strLength = mb_strlen($string);
  192. $spases = str_repeat(" ", ($length - $strLength));
  193. $string .= $spases;
  194. return $string;
  195. }
  196.  
  197.  
  198.  
  199.  
  200. $engineer = new Engineer(1, false);
  201. echo "зряплата: $engineer->salary\n";
  202.  
  203. // повысим человека за хорошую работу
  204. $engineer->rank = 2;
  205. echo "зряплата 2-го ранга: $engineer->salary\n";
  206.  
  207.  
  208.  
  209.  
Success #stdin #stdout 0.01s 24400KB
stdin
Standard input is empty
stdout
зряплата: 200
зряплата 2-го ранга: 200