Mac II
03-02-2011, 09:06 PM
Please , just tell me if it is functionality , if not give new source and i will study it , but if it is don't give new source because it is still functionality .
<?php
class Calculator {
public $x;
public $y;
public $operator;
public function calculate($x, $operator, $y) {
$this->setX($x);
$this->setY($y);
$this->setOperator($operator);
if(!isset($this->x) or !isset($this->operator) or !isset($this->y) or !is_numeric($this->x) or !is_numeric($this->y)):
throw new exception('X, operator or Y is not set or X or Y is not numeric');
else:
if($this->operator !== "+" or $this->operator !== "-" or $this->operator !== "*" or $this->operator !== "/"):
throw new invalidargumentexception('Invalid Operator');
else:
switch($this->operator):
case "+":
echo $x + $y;
break;
case "-":
echo $x - $y;
break;
case "*":
echo $x * $y;
break;
case "/":
echo $x / $y;
break;
endswitch;
endif;
endif;
}
public function setX($string) {
$this->x = $string;
}
public function setY($string) {
$this->y = $string;
}
public function setOperator($string) {
$this->operator = $string;
}
}
$obj = new Calculator;
$obj->calculate("1", "+", "1");
?>
Thanks!
<?php
class Calculator {
public $x;
public $y;
public $operator;
public function calculate($x, $operator, $y) {
$this->setX($x);
$this->setY($y);
$this->setOperator($operator);
if(!isset($this->x) or !isset($this->operator) or !isset($this->y) or !is_numeric($this->x) or !is_numeric($this->y)):
throw new exception('X, operator or Y is not set or X or Y is not numeric');
else:
if($this->operator !== "+" or $this->operator !== "-" or $this->operator !== "*" or $this->operator !== "/"):
throw new invalidargumentexception('Invalid Operator');
else:
switch($this->operator):
case "+":
echo $x + $y;
break;
case "-":
echo $x - $y;
break;
case "*":
echo $x * $y;
break;
case "/":
echo $x / $y;
break;
endswitch;
endif;
endif;
}
public function setX($string) {
$this->x = $string;
}
public function setY($string) {
$this->y = $string;
}
public function setOperator($string) {
$this->operator = $string;
}
}
$obj = new Calculator;
$obj->calculate("1", "+", "1");
?>
Thanks!