ehime

better calc

Oct 22nd, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2.  
  3.     protected $num = 0;
  4.  
  5.     public function add($int)
  6.     {
  7.         if ($this->isInRange($int)
  8.             $this->num += $int;
  9.  
  10.         return $this;
  11.     }
  12.  
  13.     public function sub($int)
  14.     {
  15.         if ($this->isInRange($int)
  16.             $this->num -= $int;
  17.  
  18.         return $this;
  19.     }
  20.  
  21.     public function mult($int)
  22.     {
  23.         if ($this->isInRange($int)
  24.             $this->num *= $int;
  25.  
  26.         return $this;
  27.     }
  28.  
  29.     public function div($int)
  30.     {
  31.         if ($this->isInRange($int)
  32.             $this->num /= $int;
  33.  
  34.         return $this;
  35.     }
  36.  
  37.     public function getTotal()
  38.     {
  39.         return $this->num;
  40.     }
  41.  
  42.     public function isInRange()
  43.     {
  44.         // could be the same as my validatePositiveInts() method I guess....
  45.         // yeah, this would work a hell of a lot better, i DID NOT include
  46.         // error exceptions though, but we could use some of it from my
  47.         // calc method, and even work it farther down to type detect for a
  48.         // more specific error.... show your guys this too maybe? should have
  49.         // though it over for a few more minutes ;)  
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment