Guest User

Untitled

a guest
Dec 14th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 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. /**
  24. * @param float $number A number.
  25. */
  26. public function add($number)
  27. {
  28. $this->result = $this->result + $number;
  29. }
  30. /**
  31. * @param float $number A number.
  32. */
  33. public function minus($number)
  34. {
  35. $this->result = $this->result - $number;
  36. }
  37. /**
  38. * @param float $number A number.
  39. */
  40. public static function multiply($number)
  41. {
  42. $this->result = $this->result * $number;
  43. }
  44. /**
  45. * @param float $number A number.
  46. */
  47. public static function divideBy($number)
  48. {
  49. $this->result = $this->result / $number;
  50. }
  51. /**
  52. * If the object is returned, the result should be displayed.
  53. *
  54. * @return string
  55. */
  56. public function result()
  57. {
  58. return $this->result;
  59. }
  60. }
Add Comment
Please, Sign In to add comment