Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Employee{
- private $id;
- private $firstName;
- private $lastName;
- private $salary;
- const MONTHS = 12;
- public function __construct($id, $firstName, $lastName, $salary)
- {
- $this->id = $id;
- $this->firstName = $firstName;
- $this->lastName = $lastName;
- $this->setSalary($salary);
- }
- public function getId()
- {
- return $this->id;
- }
- public function getFirstName()
- {
- return $this->firstName;
- }
- public function getLastName()
- {
- return $this->lastName;
- }
- public function getSalary()
- {
- return $this->salary;
- }
- public function setSalary($salary)
- {
- if($salary <= 0){
- throw new InvalidArgumentException('Salary must be greater then zero');
- }
- $this->salary = $salary;
- }
- public function getName()
- {
- return $this->firstName . ' '. $this->lastName;
- }
- public function getAnnualSalary()
- {
- return $this->salary * MONTHS;
- }
- public function raiseSalary($percent)
- {
- if($percent <= 0){
- throw new InvalidArgumentException('Percent must be greater then zero');
- }
- $this->salary += $this->salary * $percent / 100;
- return $this->salary;
- }
- public function __toString()
- {
- return sprintf('Employee[id=%d,name=%s,salary=%d]', $this->id,$this->getName(),$this->salary);
- }
- }
Add Comment
Please, Sign In to add comment