fork download
  1. <?php
  2. class Employee{
  3.  
  4. public $salary;
  5. public $cofee;
  6. public $pages;
  7.  
  8.  
  9. function __construct($name){
  10. $this->name=$name;
  11. return $this->name;
  12. }
  13.  
  14. }
  15.  
  16. class Department{
  17. public $rank;
  18. public $quantity;
  19. public $salary;
  20. public $cofee;
  21. public $pages;
  22. function __construct($name){
  23. $this->name=$name;
  24. return $this->name;
  25. }
  26.  
  27. function getSalary(){
  28. $multiply=1;
  29. switch($this->rank){
  30. case 2:
  31. $multiply=1.25;
  32. break;
  33. case 3:
  34. $multiply=1.50;
  35. break;
  36. }
  37. $getSalary=$this->salary*$multiply*$this->quantity;
  38. return $getSalary;
  39. }
  40. function getCofee(){
  41. $getCofee=$this->quantity*$this->cofee;
  42. return $getCofee;
  43. }
  44. function getPages(){
  45. $getPages=$this->quantity*$this->pages;
  46. return $getPages;
  47. }
  48.  
  49. }
  50.  
  51. function createDepartment($data){
  52. $department=new Department($data['name']);
  53. $quantity=0;
  54. $costs=0;
  55. $pages=0;
  56. $cofee=0;
  57. foreach($data as $key => $workers){
  58. if($key=="name"){
  59. continue;
  60. }
  61. $department->rank=$workers['rank'];
  62. $department->quantity=$workers['quantity'];
  63. $department->cofee=$workers['employee']->cofee;
  64. $department->pages=$workers['employee']->pages;
  65. $quantity=$quantity+$department->quantity;
  66. $department->salary=$workers['employee']->salary;
  67. $costs=$costs+$department->getSalary();
  68. $pages=$pages+$department->getPages();
  69. $cofee=$cofee+$department->getCofee();
  70.  
  71. }
  72. echo "Департамент ".$department->name;
  73. echo " \n Работников $quantity";
  74. echo " \n Расходы $costs";
  75. echo "\n Кофе $cofee";
  76. echo " \n Страниц $pages";
  77. }
  78.  
  79. $manager=new Employee("Менеджер");
  80. $manager->salary=500;
  81. $manager->cofee=20;
  82. $manager->pages=200;
  83.  
  84. $market=new Employee("Маркетолог");
  85. $market->salary=400;
  86. $market->cofee=15;
  87. $market->pages=150;
  88.  
  89. $engineer=new Employee("Инженер");
  90. $engineer->salary=200;
  91. $engineer->cofee=5;
  92. $engineer->pages=50;
  93.  
  94. $analyst=new Employee("Аналитик");
  95. $analyst->salary=800;
  96. $analyst->cofee=50;
  97. $analyst->pages=5;
  98.  
  99.  
  100. $department1=array(
  101. 'name'=>"Закупок",
  102. 'manager1'=>array(
  103. 'rank'=>1,
  104. 'quantity'=>9,
  105. 'employee'=>$manager),
  106. 'manager2'=>array(
  107. 'rank'=>2,
  108. 'quantity'=>3,
  109. 'employee'=>$manager),
  110. 'manager3'=>array(
  111. 'rank'=>3,
  112. 'quantity'=>2,
  113. 'employee'=>$manager),
  114. 'market1'=>array(
  115. 'rank'=>1,
  116. 'quantity'=>2,
  117. 'employee'=>$market)
  118.  
  119. );
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. createDepartment($department1);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Департамент Закупок 
 Работников 16 
 Расходы 8675
 Кофе  310 
 Страниц 3100