@ 2019-03-03T14:19:58Z <?php
abstract class AbstractEmployee {
protected $rank;
protected $isBoss;
public function __construct(int $rank, bool $isBoss): void {
$this->rank = $rank;
$this->isBoss = $isBoss;
}
abstract function getBasicSalary(): float;
abstract function getBasicCoffee(): float;
abstract function getBasicPages(): float;
public function getSalary(): float {
$salary = $this->getBasicSalary();
if ($this->rank == 2) {
$salary *= 1.25;
} elseif ($this->rank == 3) {
$salary *= 1.5;
}
if ($this->isBoss == true) {
$salary *= 1.5;
}
return round($salary, 1);
}
public function getCoffee(): float {
$coffee = $this->getBasicCoffee();
if ($this->isBoss == true) {
$coffee *= 2;
}
return $coffee;
}
public function getPages(): float {
$pages = $this->getBasicPages();
if ($this->isBoss == true) {
$pages = 0;
}
return $pages;
}
}
class Manager extends AbstractEmployee {
public function getBasicSalary(): float {
return 500;
}
public function getBasicCoffee(): float {
return 20;
}
public function getBasicPages(): float {
return 200;
}
}
class Marketer extends AbstractEmployee {
public function getBasicSalary(): float {
return 400;
}
public function getBasicCoffee(): float {
return 15;
}
public function getBasicPages(): float {
return 150;
}
}
class Engineer extends AbstractEmployee {
public function getBasicSalary(): float {
return 200;
}
public function getBasicCoffee(): float {
return 5;
}
public function getBasicPages(): float {
return 50;
}
}
class Analyst extends AbstractEmployee {
public function getBasicSalary(): float {
return 800;
}
public function getBasicCoffee(): float {
return 50;
}
public function getBasicPages(): float {
return 5;
}
}
class Department {
private $name;
private $employees = array();
public function __construct(string $name): void {
$this->name = $name;
}
public function addEmployees(int $count, string $profession, int $rank, bool $isBoss): void {
if ($profession == "Manager") {
for ($i = 0; $i < $count; $i++) {
$this->employees[] = new Manager($rank, $isBoss);
}
} elseif ($profession == "Marketer") {
for ($i = 0; $i < $count; $i++) {
$this->employees[] = new Marketer($rank, $isBoss);
}
} elseif ($profession == "Engineer") {
for ($i = 0; $i < $count; $i++) {
$this->employees[] = new Engineer($rank, $isBoss);
}
} elseif ($profession == "Analyst") {
for ($i = 0; $i < $count; $i++) {
$this->employees[] = new Analyst($rank, $isBoss);
}
}
}
public function getInformation(): array {
$information = array();
$information['name'] = $this->name;
$information['employeesCount'] = count($this->employees);
$information['selary'] = 0;
$information['coffee'] = 0;
$information['pages'] = 0;
foreach ($this->employees as $employee) {
$information['selary'] += $employee->getSalary();
$information['coffee'] += $employee->getCoffee();
$information['pages'] += $employee->getPages();
}
return $information;
}
}
class Vektor {
private $departments = array();
public function addDepartment (Department $department): void {
$this->departments[] = $department;
}
public function getDepartments(): array {
return $this->departments;
}
public function getDepartmentsCount(): int {
return count($this->departments);
}
}
class Table {
public function printTable (Vektor $vektor): void {
$this->printLine("Департамент", "сотр.", "тугр.", "кофе", "стр.", "тугр/стр.");
echo str_repeat("-", 70);
echo "\n";
$employeesCount = 0;
$totalSelary = 0;
$totalCoffee = 0;
$totalPages = 0;
$totalSelarySharePages = 0;
foreach ($vektor->getDepartments() as $department) {
$employeesCount += $department->getInformation()['employeesCount'];
$totalSelary += $department->getInformation()['selary'];
$totalCoffee += $department->getInformation()['coffee'];
$totalPages += $department->getInformation()['pages'];
$totalSelarySharePages += $totalSelary / $totalPages;
$this->printLine($department->getInformation()['name'],
$department->getInformation()['employeesCount'],
$department->getInformation()['selary'],
$department->getInformation()['coffee'],
$department->getInformation()['pages'],
round($department->getInformation()['selary'] / $department->getInformation()['pages']), 1);
}
echo "\n";
$this->printLine("Среднее",
round($employeesCount / $vektor->getDepartmentsCount(), 1),
round($totalSelary / $vektor->getDepartmentsCount(), 1),
round($totalCoffee / $vektor->getDepartmentsCount(), 1),
round($totalPages / $vektor->getDepartmentsCount(), 1),
round($totalSelarySharePages / $vektor->getDepartmentsCount(), 1));
$this->printLine("Всего", $employeesCount, $totalSelary, $totalCoffee, $totalPages, round($totalSelarySharePages, 1));
}
private function printLine(string $title, $employees, $salary, $coffee, $pages, $salarySharePages): void {
echo $this->padRight($title, 15);
$this->padLeft($employees, 10) .
$this->padLeft($salary, 10) .
$this->padLeft($coffee, 10) .
$this->padLeft($pages, 10) .
$this->padLeft($salarySharePages, 15);
echo "\n";
}
private function padLeft ($field, int $col): void {
echo str_repeat(" ", $col - mb_strlen($field)).$field;
}
private function padRight ($field, int $col) {
echo $field.str_repeat(" ", $col - mb_strlen($field));
}
}
$procurementDepartment = new Department("Закупок");
$procurementDepartment->addEmployees(9, "Manager", 1, false);
$procurementDepartment->addEmployees(3, "Manager", 2, false);
$procurementDepartment->addEmployees(2, "Manager", 3, false);
$procurementDepartment->addEmployees(2, "Marketer", 1, false);
$procurementDepartment->addEmployees(1, "Manager", 2, true);
$salesDepartment = new Department("Продаж");
$salesDepartment->addEmployees(12, "Manager", 1, false);
$salesDepartment->addEmployees(6, "Marketer", 1, false);
$salesDepartment->addEmployees(3, "Analyst", 1, false);
$salesDepartment->addEmployees(2, "Analyst", 2, false);
$salesDepartment->addEmployees(1, "Marketer", 2, true);
$advertisingDepartment = new Department("Рекламы");
$advertisingDepartment->addEmployees(15, "Marketer", 1, false);
$advertisingDepartment->addEmployees(10, "Marketer", 2, false);
$advertisingDepartment->addEmployees(8, "Manager", 1, false);
$advertisingDepartment->addEmployees(2, "Engineer", 1, false);
$advertisingDepartment->addEmployees(1, "Marketer", 3, true);
$logisticsDepartment = new Department("Логистики");
$logisticsDepartment->addEmployees(13, "Manager", 1, false);
$logisticsDepartment->addEmployees(5, "Manager", 2, false);
$logisticsDepartment->addEmployees(5, "Engineer", 1, false);
$logisticsDepartment->addEmployees(1, "Manager", 1, true);
$vektor = new Vektor();
$vektor->addDepartment($procurementDepartment);
$vektor->addDepartment($salesDepartment);
$vektor->addDepartment($advertisingDepartment);
$vektor->addDepartment($logisticsDepartment);
$table = new Table();
$table->printTable($vektor);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.3.2 0.066 0.006 14.60 7.3.1 0.042 0.013 14.70 7.3.0 0.057 0.000 14.70 7.2.15 0.042 0.016 15.08 7.2.14 0.059 0.007 14.90 7.2.13 0.054 0.006 14.34 7.2.12 0.067 0.010 14.59 7.2.11 0.046 0.014 14.71 7.2.10 0.038 0.014 14.53 7.2.9 0.035 0.016 14.27 7.2.8 0.048 0.006 14.39 7.2.7 0.055 0.003 14.91 7.2.6 0.057 0.003 14.45 7.2.5 0.052 0.003 14.45 7.2.4 0.041 0.003 14.84 7.2.3 0.039 0.011 14.74 7.2.2 0.049 0.000 15.04 7.2.1 0.117 0.010 14.80 7.2.0 0.035 0.000 15.09 7.1.25 0.053 0.000 13.73
preferences:dark mode live preview
144.16 ms | 1394 KiB | 7 Q