Guest User

Untitled

a guest
Jul 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2. class Employee{
  3.  
  4. private $id;
  5. private $firstName;
  6. private $lastName;
  7. private $salary;
  8.  
  9. const MONTHS = 12;
  10.  
  11. public function __construct($id, $firstName, $lastName, $salary)
  12. {
  13. $this->id = $id;
  14. $this->firstName = $firstName;
  15. $this->lastName = $lastName;
  16. $this->setSalary($salary);
  17. }
  18.  
  19. public function getId()
  20. {
  21. return $this->id;
  22. }
  23.  
  24. public function getFirstName()
  25. {
  26. return $this->firstName;
  27. }
  28.  
  29. public function getLastName()
  30. {
  31. return $this->lastName;
  32. }
  33.  
  34. public function getSalary()
  35. {
  36. return $this->salary;
  37. }
  38.  
  39. public function setSalary($salary)
  40. {
  41. if($salary <= 0){
  42. throw new InvalidArgumentException('Salary must be greater then zero');
  43. }
  44. $this->salary = $salary;
  45. }
  46.  
  47. public function getName()
  48. {
  49. return $this->firstName . ' '. $this->lastName;
  50. }
  51.  
  52. public function getAnnualSalary()
  53. {
  54. return $this->salary * MONTHS;
  55. }
  56.  
  57. public function raiseSalary($percent)
  58. {
  59. if($percent <= 0){
  60. throw new InvalidArgumentException('Percent must be greater then zero');
  61. }
  62. $this->salary += $this->salary * $percent / 100;
  63. return $this->salary;
  64. }
  65.  
  66. public function __toString()
  67. {
  68. return sprintf('Employee[id=%d,name=%s,salary=%d]', $this->id,$this->getName(),$this->salary);
  69. }
  70. }
Add Comment
Please, Sign In to add comment