Guest User

Untitled

a guest
Sep 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. class Weight
  2. {
  3. protected $weight;
  4.  
  5. public function __construct($weight)
  6. {
  7. $this->weight = $weight;
  8. }
  9.  
  10. public function gain($kilograms)
  11. {
  12. return new static($this->weight + $kilograms);
  13. }
  14.  
  15.  
  16. public function loose($kilograms)
  17. {
  18. return new static($this->weight - $kilograms);
  19. }
  20.  
  21.  
  22. }
  23.  
  24. class GymMember
  25. {
  26. protected $name;
  27. protected $weight;
  28.  
  29.  
  30. public function __construct($name, Weight $weight)
  31. {
  32. $this->name = $name;
  33. $this->weight = $weight;
  34. }
  35.  
  36.  
  37. public function workoutFor(TimeLength $length)
  38. {
  39.  
  40. if(!$length->inSeconds() > (40 * 60 ))
  41. {
  42. return 'Keep up the good work!';
  43. }
  44.  
  45. $this->weight->loose(2);
  46.  
  47. }
  48.  
  49. }
  50.  
  51. class TimeLength
  52. {
  53.  
  54. protected $seconds;
  55.  
  56.  
  57. private function __construct($seconds)
  58. {
  59. $this->seconds = $seconds;
  60. }
  61.  
  62.  
  63. public static function Minutes($minutes)
  64. {
  65. return new static($minutes * 60);
  66. }
  67.  
  68.  
  69. public function inSeconds()
  70. {
  71. return $this->seconds;
  72. }
  73.  
  74.  
  75. public function inMinutes()
  76. {
  77. return $this->seconds / 60;
  78. }
  79.  
  80.  
  81. public function inHours()
  82. {
  83. return $this->seconds / 60 / 60;
  84. }
  85.  
  86. }
  87.  
  88. $gymMember = new GymMember('MTROBERT', new Weight(78));
  89.  
  90. $gymMember->workOutFor(Timelength::minutes(45));
  91.  
  92.  
  93.  
  94. var_dump($gymMember);
  95.  
  96. public function workoutFor(TimeLength $length)
  97. {
  98.  
  99. // ...
  100.  
  101. $this->weight->loose(2);
  102.  
  103. }
  104.  
  105. $this->weight = $this->weight->loose(2);
  106.  
  107. public function loose($kilograms)
  108. {
  109. $this->weight -= $kilograms;
  110. }
Add Comment
Please, Sign In to add comment