<?php
abstract class Worker {
public $name;
public $level;
public $chief;
public $coffe;
public $paid;
public $pages;
public function drinkCoffe() {
if ($this->chief) {
return ($this->coffe *2);
} else {
return $this->coffe;
}
}
public function getPaid() {
if ($this->level == 3) { $cof = 1.5; } elseif ($this->level == 2) { $cof = 1.25; } elseif ($this->level == 1) { $cof = 1;} else { echo "Invalid level\n"; die;} if ($this->chief) {
$paid = $this->paid * 2 * $cof;
return $paid;
} else {
$paid = $this->paid * $cof;
return $paid;
}
}
public function getUseCof() { // Получаем отношения деньги/страницы
if ($this->pages == 0) {
return $this->getPaid();
} else {
$rate = $this->getPaid() / $this-> pages;
return $rate;
}
}
}
class Manager extends Worker {
public function __construct($name, $level, $chief) {
$this->name = $name;
$this->level = $level;
$this->chief = $chief;
$this->coffe = 20;
$this->paid = 500;
$this->paid = $this->getPaid();
if ($this->chief) {
$this->pages = 0;
} else {
$this->pages = 200;
}
}
}
class Engeneer extends Worker {
public function __construct($name, $level, $chief) {
$this->name = $name;
$this->level = $level;
$this->chief = $chief;
$this->coffe = 5;
$this->paid = 200;
$this->paid = $this->getPaid();
if ($this->chief) {
$this->pages = 0;
} else {
$this->pages = 50;
}
}
}
class Marketing extends Worker {
public function __construct($name, $level, $chief) {
$this->name = $name;
$this->level = $level;
$this->chief = $chief;
$this->coffe = 15;
$this->paid = 400;
$this->paid = $this->getPaid();
if ($this->chief) {
$this->pages = 0;
} else {
$this->pages = 150;
}
}
}
class Analyst extends Worker {
public function __construct($name, $level, $chief) {
$this->name = $name;
$this->level = $level;
$this->chief = $chief;
$this->coffe = 50;
$this->paid = 800;
$this->paid = $this->getPaid();
if ($this->chief) {
$this->pages = 0;
} else {
$this->pages = 5;
}
}
}
function rightPad($string, $symbols) {
if ($len < $symbols) {
$add = $symbols - $len;
return ($string.str_pad("", $add)); } else {
return $string;
}
}
function leftPad($string, $symbols) {
if ($len < $symbols) {
$add = $symbols - $len;
return (str_pad("", $add).$string); } else {
return $string;
}
}
class Departament {
public $name;
public $workers;
public function __construct($name){
$this->name = $name;
$this->workers = array(); }
public function addWorkers($example, $count) {
$array_count = count($this->workers); for ($i = $array_count; $i <= ($array_count + $count); $i++) {
$this->workers[] = $example;
}
}
public function totalySalary() {
$total = 0;
foreach ($this->workers as $key => $value) {
$total += $this->workers[$key]->paid;
}
return $total;
}
public function totalyCoffe() {
$totalyCoffe = 0;
foreach ($this->workers as $key => $value) {
$totalyCoffe += $this->workers[$key]->coffe;
}
return $totalyCoffe;
}
public function totalyPages() {
$totalyPages = 0;
foreach ($this->workers as $key => $value) {
$totalyPages += $this->workers[$key]->pages;
}
return $totalyPages;
}
public function averagePrice() {
$price = 0;
foreach ($this->workers as $key => $value) {
$price += $this->workers[$key]->getUseCof();
}
return $price/count($this->workers); }
}
$manager1L = new Manager('Петров И.', 1, False);
$manager2L = new Manager('Иванов П.', 2, False);
$manager3L = new Manager('Рустамович Ш.', 3, False);
$chiefMa2 = new Manager("Шеф", 2, True);
$chiefMarket2 = new Marketing("Шеф", 2, True);
$marketing1L = new Marketing('Шухратович Р', 3, False);
$analyst1L = new Analyst('Доброевский Р.', 3, False);
$analyst2L = new Analyst('Вербицкий М.', 2, False);
$buying = new Departament('Закупок');
$buying->addWorkers($manager1L, 9);
$buying->addWorkers($manager2L, 3);
$buying->addWorkers($manager3L, 2);
$buying->addWorkers($marketing1L, 1);
$buying->addWorkers($chiefMa2, 1);
$selling = new Departament('Продаж');
$selling->addWorkers($manager1L, 12);
$selling->addWorkers($marketing1L, 6);
$selling->addWorkers($analyst1L, 3);
$selling->addWorkers($analyst2L, 2);
$selling->addWorkers($chiefMarket2, 1);
$departaments[] = $buying;
$departaments[] = $selling;
$col = 20;
$table = array ('Департамент', 'Сотрудников', 'Тугр.', 'Кофе', 'Стр', 'Т/СТР'); foreach ($table as $key => $value) {
echo rightPad($table[$key], $col);
}
echo "\n";
foreach ($departaments as $key => $value) {
echo rightPad($departaments[$key]->name, $col);
echo rightPad
(count($departaments[$key]->workers), $col); echo rightPad($departaments[$key]->totalySalary(), $col);
echo rightPad($departaments[$key]->totalyCoffe(), $col);
echo rightPad($departaments[$key]->totalyPages(), $col);
echo rightPad
(ceil($departaments[$key]->averagePrice()), $col); echo "\n";
}
?>