public function quotient() {
if( $this->number2 == 0 ) {
throw new Exception( 'division by zero' );
}
return $this->number1 / $this->number2;
}
| eg.Calc | ||
| number1 | number2 | quotient() |
| 4 | 2 | 2 |
| 9 | 0 | division by zero! |
| 4 | 0 | 2 |
| 6 | 3 | 2 |
| 21 | 7 | 3 |
| 9 | 6 | 1.5 |
| 12 | 3 | 4 |
| 2 | 2 | 1 |
| 10 | 5 | 1.9 |
public function sum() {
return $this->number1 + $this->number2;
}
| eg.Calc | ||
| number1 | number2 | sum() |
| 2 | 2 | 4 |
| 6 | 2 | 9 |
public function sub() {
return $this->number1 - $this->number2;
}
| eg.Calc | ||
| number1 | number2 | sub() |
| 2 | 2 | 1 |
| 2 | 4 | -2 |