fork download
  1. <?php
  2.  
  3. /* Вектор */
  4.  
  5.  
  6. class Employee {
  7. private $name = null;
  8. private $rank = 1;
  9. private $occupation = null;
  10. private $boss = 0;
  11.  
  12. public function getName() {
  13. return $this->name;
  14. }
  15.  
  16. public function getRank() {
  17. return $this->rank;
  18. }
  19.  
  20. public function getOccupation() {
  21. return $this->occupation;
  22. }
  23.  
  24. public function isBoss() {
  25. return $this->boss;
  26. }
  27.  
  28. public function __construct($name, $rank, $occupation, $boss) {
  29. $this->name = $name;
  30. $this->rank = $rank;
  31. $this->occupation = $occupation;
  32. $this->boss = $boss;
  33. }
  34. }
  35.  
  36. class Department {
  37. private $name = null;
  38. private $employees = array();
  39.  
  40. public function getName() {
  41. return $this->name;
  42. }
  43.  
  44. public function getEmployees() {
  45. return $this->employees;
  46. }
  47.  
  48. private function addEmployee(Employee $employee) {
  49. array_push($this->employees, $employee);
  50. }
  51.  
  52. public function hireEmployee($occupation, $rank, $boss) {
  53. $name = $occupation . " " .(string) $rank;
  54. if ($boss) {
  55. $name = $name . "(босс)";
  56. }
  57.  
  58. $this->addEmployee(new Employee($name, $rank, $occupation, $boss));
  59. }
  60.  
  61. public function getStatistics() {
  62. $totalExpenses = 0;
  63. $totalCofeConsumption = 0;
  64. $totalPaperProduction = 0;
  65.  
  66. foreach ($this->employees as $name => $employee) {
  67. $salary = 0;
  68. $cofeConsumption = 0;
  69. $paperProduction = 0;
  70.  
  71. switch($employee->getOccupation()) {
  72. case "аналтик":
  73. $salary = 800;
  74. $cofeConsumption = 50;
  75. $paperProduction = 5;
  76. break;
  77. case "инженер":
  78. $salary = 200;
  79. $cofeConsumption = 5;
  80. $paperProduction = 50;
  81. break;
  82. case "маркетолог":
  83. $salary = 400;
  84. $cofeConsumption = 15;
  85. $paperProduction = 150;
  86. break;
  87. case "менеджер":
  88. $salary = 500;
  89. $cofeConsumption = 20;
  90. $paperProduction = 200;
  91. break;
  92. }
  93.  
  94. switch($employee->getRank()){
  95. case 2:
  96. $salary *= 1.25;
  97. break;
  98. case 3:
  99. $salary *= 1.5;
  100. break;
  101. }
  102.  
  103. if ($employee->isBoss()) {
  104. $salary *= 1.5;
  105. $cofeConsumption *= 2;
  106. $paperProduction = 0;
  107. }
  108.  
  109. $totalExpenses += $salary;
  110. $totalCofeConsumption += $cofeConsumption;
  111. $totalPaperProduction += $paperProduction;
  112. }
  113.  
  114. $statistics = array(
  115. "totalExpenses" => $totalExpenses,
  116. "totalCofeConsumption" => $totalCofeConsumption,
  117. "totalPaperProduction" => $totalPaperProduction,
  118. "numberOfEmployees" => count($this->employees)
  119. );
  120. if (($expensesPerPage = ($totalExpenses / $totalPaperProduction)) != 0) {
  121. $statistics["expensesPerPage"] = $expensesPerPage;
  122. } else {
  123. $statistics["expensesPerPage"] = 0;
  124. }
  125.  
  126. return $statistics;
  127. }
  128.  
  129. public function __construct($name) {
  130. $this->name = $name;
  131. }
  132. }
  133.  
  134. class Company {
  135. private $name = null;
  136. private $departments = array();
  137.  
  138. public function getName() {
  139. return $this->name;
  140. }
  141.  
  142. public function getDepartments(){
  143. return $this->departments;
  144. }
  145.  
  146. public function createDepartment($name) {
  147. $this->departments[$name] = new Department($name);
  148. }
  149.  
  150. public function hireEmployee($occupation, $rank, $boss, $department) {
  151. $this->departments[$department]->hireEmployee($occupation, $rank, $boss);
  152. }
  153.  
  154. public function getStatistics() {
  155. $numberOfEmployees = 0;
  156. $totalCofeConsumption = 0;
  157. $totalPaperProduction = 0;
  158. $expensesPerPage = 0;
  159. $totalExpenses = 0;
  160.  
  161. foreach ($this->departments as $name => $department) {
  162. $statistics = $department->getStatistics();
  163. var_dump($statistics);
  164. $totalExpenses += $statistics["totalExpenses"];
  165. $totalCofeConsumption += $statistics["totalCofeConsumption"];
  166. $totalPaperProduction += $statistics["totalPaperProduction"];
  167. $numberOfEmployees += $statistics["numberOfEmployees"];
  168. $expensesPerPage += $statistics["expensesPerPage"];
  169. }
  170.  
  171. $statistics = array(
  172. "totalExpenses" => $totalExpenses,
  173. "totalCofeConsumption" => $totalCofeConsumption,
  174. "totalPaperProduction" => $totalPaperProduction,
  175. "numberOfEmployees" => $numberOfEmployees,
  176. "numberOfDepartments" => count($this->departments)
  177. );
  178. if (($expensesPerPage = ($totalExpenses / $totalPaperProduction)) != 0) {
  179. $statistics["expensesPerPage"] = $expensesPerPage;
  180. } else {
  181. $statistics["expensesPerPage"] = 0;
  182. }
  183.  
  184. var_dump($statistics);
  185. return $statistics;
  186. }
  187.  
  188. public function __construct($name) {
  189. $this->name = $name;
  190. }
  191. }
  192.  
  193. $vector = new Company("Вектор");
  194. $vector->createDepartment("Департамент рекламы");
  195. $vector->hireEmployee("менеджер", 3, 0, "Департамент рекламы");
  196. $vector->hireEmployee("аналитик", 2, 0, "Департамент рекламы");
  197. $vector->hireEmployee("инженер", 3, 0, "Департамент рекламы");
  198. $vector->hireEmployee("маркетолог", 3, 1, "Департамент рекламы");
  199. $vector->createDepartment("Департамент управления");
  200. $vector->hireEmployee("менеджер", 3, 1, "Департамент управления");
  201. $vector->hireEmployee("аналитик", 1, 0, "Департамент управления");
  202. $vector->hireEmployee("аналитик", 2, 0, "Департамент управления");
  203. $vector->hireEmployee("менеджер", 3, 0, "Департамент управления");
  204. $vector->getStatistics();
  205. var_dump($vector);
  206. ?>
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
array(5) {
  ["totalExpenses"]=>
  float(1950)
  ["totalCofeConsumption"]=>
  int(55)
  ["totalPaperProduction"]=>
  int(250)
  ["numberOfEmployees"]=>
  int(4)
  ["expensesPerPage"]=>
  float(7.8)
}
array(5) {
  ["totalExpenses"]=>
  float(1875)
  ["totalCofeConsumption"]=>
  int(60)
  ["totalPaperProduction"]=>
  int(200)
  ["numberOfEmployees"]=>
  int(4)
  ["expensesPerPage"]=>
  float(9.375)
}
array(6) {
  ["totalExpenses"]=>
  float(3825)
  ["totalCofeConsumption"]=>
  int(115)
  ["totalPaperProduction"]=>
  int(450)
  ["numberOfEmployees"]=>
  int(8)
  ["numberOfDepartments"]=>
  int(2)
  ["expensesPerPage"]=>
  float(8.5)
}
object(Company)#1 (2) {
  ["name":"Company":private]=>
  string(12) "Вектор"
  ["departments":"Company":private]=>
  array(2) {
    ["Департамент рекламы"]=>
    object(Department)#2 (2) {
      ["name":"Department":private]=>
      string(37) "Департамент рекламы"
      ["employees":"Department":private]=>
      array(4) {
        [0]=>
        object(Employee)#3 (4) {
          ["name":"Employee":private]=>
          string(18) "менеджер 3"
          ["rank":"Employee":private]=>
          int(3)
          ["occupation":"Employee":private]=>
          string(16) "менеджер"
          ["boss":"Employee":private]=>
          int(0)
        }
        [1]=>
        object(Employee)#4 (4) {
          ["name":"Employee":private]=>
          string(18) "аналитик 2"
          ["rank":"Employee":private]=>
          int(2)
          ["occupation":"Employee":private]=>
          string(16) "аналитик"
          ["boss":"Employee":private]=>
          int(0)
        }
        [2]=>
        object(Employee)#5 (4) {
          ["name":"Employee":private]=>
          string(16) "инженер 3"
          ["rank":"Employee":private]=>
          int(3)
          ["occupation":"Employee":private]=>
          string(14) "инженер"
          ["boss":"Employee":private]=>
          int(0)
        }
        [3]=>
        object(Employee)#6 (4) {
          ["name":"Employee":private]=>
          string(32) "маркетолог 3(босс)"
          ["rank":"Employee":private]=>
          int(3)
          ["occupation":"Employee":private]=>
          string(20) "маркетолог"
          ["boss":"Employee":private]=>
          int(1)
        }
      }
    }
    ["Департамент управления"]=>
    object(Department)#7 (2) {
      ["name":"Department":private]=>
      string(43) "Департамент управления"
      ["employees":"Department":private]=>
      array(4) {
        [0]=>
        object(Employee)#8 (4) {
          ["name":"Employee":private]=>
          string(28) "менеджер 3(босс)"
          ["rank":"Employee":private]=>
          int(3)
          ["occupation":"Employee":private]=>
          string(16) "менеджер"
          ["boss":"Employee":private]=>
          int(1)
        }
        [1]=>
        object(Employee)#9 (4) {
          ["name":"Employee":private]=>
          string(18) "аналитик 1"
          ["rank":"Employee":private]=>
          int(1)
          ["occupation":"Employee":private]=>
          string(16) "аналитик"
          ["boss":"Employee":private]=>
          int(0)
        }
        [2]=>
        object(Employee)#10 (4) {
          ["name":"Employee":private]=>
          string(18) "аналитик 2"
          ["rank":"Employee":private]=>
          int(2)
          ["occupation":"Employee":private]=>
          string(16) "аналитик"
          ["boss":"Employee":private]=>
          int(0)
        }
        [3]=>
        object(Employee)#11 (4) {
          ["name":"Employee":private]=>
          string(18) "менеджер 3"
          ["rank":"Employee":private]=>
          int(3)
          ["occupation":"Employee":private]=>
          string(16) "менеджер"
          ["boss":"Employee":private]=>
          int(0)
        }
      }
    }
  }
}