Guest User

Untitled

a guest
Dec 14th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. <?php
  2. namespace SolvoLabs;
  3. /**
  4. * This class is used to realize some basic calculations.
  5. * For training purposes only, use bc_math functions instead.
  6. * @author Mickaƫl Andrieu <mickael.andrieu@solvolabs.com>
  7. */
  8. class Calculator{
  9. /**
  10. * @var float The result to display.
  11. */
  12. private $result;
  13. /**
  14. * Creates the Calculator.
  15. *
  16. * @param float $initialValue
  17. */
  18. public function __construct($initialValue = 0)
  19. {
  20. $this->result = $initialValue;
  21. }
  22. /**
  23. * @param float $number A number.
  24. */
  25. public function add($number)
  26. {
  27. $this->result = $this->result + $number;
  28. }
  29. /**
  30. * @param float $number A number.
  31. */
  32. public function minus($number)
  33. {
  34. $this->result = $this->result - $number;
  35. }
  36. /**
  37. * @param float $number A number.
  38. */
  39. public static function multiply($number)
  40. {$this->result = $this->result * $number;
  41. }
  42. /**
  43. * @param float $number A number.
  44. */
  45. public static function divideBy($number)
  46. {
  47. $this->result = $this->result / $number;
  48. }
  49. /**
  50. * If the object is returned, the result should be displayed.
  51. *
  52. * @return string
  53. */
  54. public function result()
  55. {
  56. return $this->result;
  57. }
  58. }
Add Comment
Please, Sign In to add comment