<?php
class Employee // employee значит «сотрудник»
{
public $name; // имя-фамилия
public $rate; // часовая ставка (сколько он получает тугриков за час работы)
public $hours = array(); // массив, содержащий отработанные часы по неделям
/* Считает общее число отработанных часов */
public function getTotalHoursWorked()
{
// Просто складываем значения часов в массиве
}
/* Считает зарплату */
public function getSalary()
{
// Получаем число отработанных часов
$hours = $this->getTotalHoursWorked();
// и умножаем на часовую ставку
$salary = $hours * $this->rate;
return $salary;
}
/* "Волшебный" метод */
public function __construct($name, $rate)
{
// задаем имя и часовую ставку
$this->name = $name;
$this->rate = $rate;
}
public function getNormalHours() {
$normalHours = 0;
foreach ($this->hours as $hoursAWeek) {
if ($hoursAWeek <= 40) {
$normalHours += $hoursAWeek;
}
}
return $normalHours;
}
public function getOvertimeHours() {
$overtime = 0;
foreach ($this->hours as $hoursAWeek) {
if ($hoursAWeek > 40) {
$overtime += ($hoursAWeek - 40);
}
}
return $overtime;
}
}
function padRight($x, $y){
return $tableCell;
}
function padLeft($x, $y){
return $tableCell;
}
// Ширина колонок
$col1 = 20;
$col2 = $col4 = $col5 = 8;
$col3 = 10;
$ivan = new Employee("Иванов Иван", 10);
// name и rate заданы через конструктор, потому осталось лишь написать часы
$ivan->hours = array(40, 40, 40, 40); // Иван работает по 40 часов в неделю
$peter = new Employee("Петров Петр", 8);
$peter->hours = array(40, 10, 40, 50); // но в последнюю неделю решил поработать побольше
$employees = array($ivan, $peter);
// Заголовок таблицы
echo padRight("Сотрудник", $col1) .
padLeft("Часы", $col2) .
padLeft("Овертайм", $col3) .
padLeft("Ставка", $col4) .
padLeft("З/п", $col5) . "\n";
// Сама таблица
$overtime = 0;
foreach ($employees as $employee) {
echo padRight($employee->name, $col1) .
padLeft($employee->getTotalHoursWorked(), $col2) .
padLeft($employee->getOvertimeHours(), $col3) .
padLeft($employee->rate, $col4) .
padLeft($employee->getSalary(), $col5) . "\n";
if ($employee->getOvertimeHours() > 0) {
$overtime += $employee->getOvertimeHours();
}
};
$salary = $overtime * $employee->rate;
echo padRight("Всего:", $col1) .
padLeft($ivan->getTotalHoursWorked() + $peter->getTotalHoursWorked(), $col2) .
padLeft($overtime, $col3) .
padLeft(null, $col4) .
padLeft($ivan->getSalary() + $peter->getSalary(), $col5) . "\n";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7Cm1iX2ludGVybmFsX2VuY29kaW5nKCJVVEYtOCIpOwoKY2xhc3MgRW1wbG95ZWUgICAgICAgICAgICAgIC8vIGVtcGxveWVlINC30L3QsNGH0LjRgiDCq9GB0L7RgtGA0YPQtNC90LjQusK7CnsKICAgIHB1YmxpYyAkbmFtZTsgICAgICAgICAgICAgICAvLyDQuNC80Y8t0YTQsNC80LjQu9C40Y8KICAgIHB1YmxpYyAkcmF0ZTsgICAgICAgICAgICAgICAvLyDRh9Cw0YHQvtCy0LDRjyDRgdGC0LDQstC60LAgKNGB0LrQvtC70YzQutC+INC+0L0g0L/QvtC70YPRh9Cw0LXRgiDRgtGD0LPRgNC40LrQvtCyINC30LAg0YfQsNGBINGA0LDQsdC+0YLRiykKICAgIHB1YmxpYyAkaG91cnMgPSBhcnJheSgpOyAgICAvLyDQvNCw0YHRgdC40LIsINGB0L7QtNC10YDQttCw0YnQuNC5INC+0YLRgNCw0LHQvtGC0LDQvdC90YvQtSDRh9Cw0YHRiyDQv9C+INC90LXQtNC10LvRj9C8CgogICAgLyog0KHRh9C40YLQsNC10YIg0L7QsdGJ0LXQtSDRh9C40YHQu9C+INC+0YLRgNCw0LHQvtGC0LDQvdC90YvRhSDRh9Cw0YHQvtCyICovCiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0VG90YWxIb3Vyc1dvcmtlZCgpCiAgICB7CiAgICAgICAgLy8g0J/RgNC+0YHRgtC+INGB0LrQu9Cw0LTRi9Cy0LDQtdC8INC30L3QsNGH0LXQvdC40Y8g0YfQsNGB0L7QsiDQsiDQvNCw0YHRgdC40LLQtQogICAgICAgIHJldHVybiBhcnJheV9zdW0oJHRoaXMtPmhvdXJzKTs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