@ 2019-03-03T14:20:25Z <?php
abstract class AbstractEmployee {
protected $rank;
protected $isBoss;
public function __construct(int $rank, bool $isBoss) {
$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) {
$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) 8.3.6 0.010 0.010 18.31 8.3.5 0.006 0.009 18.30 8.3.4 0.010 0.010 18.95 8.3.3 0.003 0.013 19.09 8.3.2 0.005 0.003 21.01 8.3.1 0.009 0.000 20.66 8.3.0 0.009 0.000 20.83 8.2.18 0.009 0.006 18.66 8.2.17 0.014 0.007 22.96 8.2.16 0.011 0.004 22.26 8.2.15 0.004 0.004 24.18 8.2.14 0.004 0.004 24.66 8.2.13 0.000 0.008 26.16 8.2.12 0.000 0.008 20.08 8.2.11 0.009 0.000 20.78 8.2.10 0.004 0.009 18.16 8.2.9 0.000 0.008 20.71 8.2.8 0.004 0.004 18.05 8.2.7 0.005 0.005 18.30 8.2.6 0.004 0.004 18.47 8.2.5 0.009 0.000 18.10 8.2.4 0.000 0.008 19.67 8.2.3 0.003 0.006 19.38 8.2.2 0.008 0.000 18.24 8.2.1 0.008 0.000 19.70 8.2.0 0.004 0.004 18.19 8.1.28 0.016 0.006 25.92 8.1.27 0.005 0.003 20.53 8.1.26 0.004 0.004 26.35 8.1.25 0.012 0.003 28.09 8.1.24 0.004 0.015 23.86 8.1.23 0.006 0.006 21.16 8.1.22 0.003 0.006 18.04 8.1.21 0.003 0.005 19.29 8.1.20 0.005 0.005 17.60 8.1.19 0.003 0.006 17.64 8.1.18 0.000 0.009 18.10 8.1.17 0.003 0.006 18.84 8.1.16 0.004 0.004 19.05 8.1.15 0.005 0.003 19.07 8.1.14 0.004 0.004 20.38 8.1.13 0.005 0.003 20.36 8.1.12 0.005 0.003 17.68 8.1.11 0.004 0.004 17.57 8.1.10 0.009 0.003 17.63 8.1.9 0.004 0.004 17.55 8.1.8 0.000 0.009 17.57 8.1.7 0.000 0.008 17.66 8.1.6 0.003 0.006 17.78 8.1.5 0.005 0.005 17.67 8.1.4 0.008 0.000 17.75 8.1.3 0.006 0.003 17.80 8.1.2 0.004 0.004 17.88 8.1.1 0.006 0.003 17.90 8.1.0 0.008 0.000 17.77 8.0.30 0.006 0.003 20.13 8.0.29 0.006 0.003 17.00 8.0.28 0.000 0.009 18.71 8.0.27 0.003 0.006 17.14 8.0.26 0.000 0.007 18.63 8.0.25 0.004 0.004 17.24 8.0.24 0.000 0.007 17.12 8.0.23 0.004 0.004 17.18 8.0.22 0.006 0.003 17.30 8.0.21 0.009 0.000 17.20 8.0.20 0.000 0.011 17.16 8.0.19 0.005 0.003 17.28 8.0.18 0.003 0.006 17.13 8.0.17 0.004 0.004 17.27 8.0.16 0.004 0.004 17.15 8.0.15 0.004 0.004 17.05 8.0.14 0.000 0.008 17.16 8.0.13 0.006 0.000 13.63 8.0.12 0.003 0.006 17.09 8.0.11 0.000 0.009 17.23 8.0.10 0.000 0.008 17.28 8.0.9 0.000 0.008 17.19 8.0.8 0.003 0.013 17.25 8.0.7 0.005 0.003 17.22 8.0.6 0.003 0.006 17.29 8.0.5 0.008 0.000 17.10 8.0.3 0.011 0.009 17.35 8.0.2 0.016 0.005 17.40 8.0.1 0.005 0.003 17.05 8.0.0 0.008 0.017 17.01 7.4.33 0.000 0.005 15.55 7.4.32 0.008 0.000 16.82 7.4.30 0.003 0.003 16.79 7.4.29 0.004 0.004 16.80 7.4.28 0.000 0.008 16.61 7.4.27 0.007 0.003 16.72 7.4.26 0.008 0.000 16.80 7.4.25 0.005 0.005 16.84 7.4.24 0.004 0.004 16.77 7.4.23 0.004 0.004 16.70 7.4.22 0.006 0.003 16.50 7.4.21 0.011 0.010 16.88 7.4.20 0.008 0.000 16.84 7.4.16 0.008 0.010 16.71 7.4.14 0.009 0.009 17.86 7.4.13 0.032 0.032 16.72 7.4.12 0.004 0.014 16.68 7.4.11 0.011 0.008 16.58 7.4.10 0.007 0.017 16.65 7.4.9 0.011 0.011 16.56 7.4.8 0.012 0.006 19.39 7.4.7 0.008 0.011 16.67 7.4.6 0.015 0.009 16.70 7.4.5 0.008 0.008 16.55 7.4.4 0.016 0.014 16.71 7.4.0 0.005 0.010 15.07 7.3.33 0.000 0.006 13.49 7.3.32 0.007 0.000 13.42 7.3.31 0.004 0.004 16.56 7.3.30 0.000 0.008 16.51 7.3.29 0.004 0.004 16.41 7.3.28 0.008 0.009 16.57 7.3.26 0.011 0.014 16.71 7.3.24 0.009 0.012 16.60 7.3.23 0.016 0.003 16.68 7.3.21 0.007 0.011 16.77 7.3.20 0.007 0.011 16.64 7.3.19 0.009 0.009 16.86 7.3.18 0.009 0.012 16.65 7.3.17 0.013 0.010 16.50 7.3.16 0.007 0.011 16.58 7.3.12 0.010 0.010 15.25 7.3.11 0.006 0.012 14.67 7.3.10 0.003 0.013 15.21 7.3.9 0.003 0.012 15.11 7.3.8 0.010 0.007 15.14 7.3.7 0.004 0.012 15.02 7.3.6 0.006 0.009 15.11 7.3.5 0.004 0.011 14.81 7.3.4 0.003 0.013 14.91 7.3.3 0.009 0.003 14.97 7.3.2 0.035 0.006 15.49 7.3.1 0.035 0.009 15.40 7.3.0 0.038 0.008 15.56 7.2.33 0.009 0.009 17.07 7.2.32 0.010 0.014 16.95 7.2.31 0.006 0.012 16.89 7.2.30 0.011 0.014 16.66 7.2.29 0.007 0.010 16.87 7.2.25 0.009 0.009 15.44 7.2.24 0.015 0.006 15.43 7.2.23 0.013 0.003 15.24 7.2.22 0.000 0.012 15.39 7.2.21 0.010 0.000 15.05 7.2.20 0.010 0.007 15.19 7.2.19 0.006 0.009 14.98 7.2.18 0.007 0.007 15.29 7.2.17 0.012 0.004 15.14 7.2.15 0.056 0.010 15.24 7.2.14 0.044 0.012 15.07 7.2.13 0.049 0.005 15.05 7.2.12 0.058 0.005 15.08 7.2.11 0.047 0.008 15.26 7.2.10 0.048 0.011 15.21 7.2.9 0.050 0.008 15.04 7.2.8 0.047 0.007 15.14 7.2.7 0.046 0.009 15.21 7.2.6 0.031 0.008 15.08 7.2.5 0.058 0.010 15.05 7.2.4 0.049 0.004 15.34 7.2.3 0.054 0.007 15.24 7.2.2 0.051 0.009 15.33 7.2.1 0.049 0.009 15.20 7.2.0 0.048 0.007 15.08 7.1.33 0.009 0.006 15.81 7.1.32 0.007 0.003 15.86 7.1.31 0.003 0.013 15.98 7.1.30 0.000 0.012 15.55 7.1.29 0.007 0.011 15.86 7.1.28 0.000 0.010 15.77 7.1.27 0.006 0.006 15.84 7.1.26 0.004 0.015 15.83 7.1.25 0.056 0.005 14.21
preferences:dark mode live preview
58.25 ms | 400 KiB | 5 Q