View Single Post
Old 03-02-2011, 09:06 PM   PM User | #1
Mac II
New to the CF scene

 
Join Date: Feb 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Mac II is an unknown quantity at this point
OOP Calculator [Mac] (What you think about that code ?)

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 Code:
<?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->$string;
    }
    public function 
setY($string) {
        
$this->$string;
    }
    public function 
setOperator($string) {
        
$this->operator $string;
    }
}
$obj = new Calculator;
$obj->calculate("1""+""1");
?>
Thanks!

Last edited by Mac II; 03-02-2011 at 09:11 PM..
Mac II is offline   Reply With Quote