

#import "Calculator.h"

@implementation Calculator
//根据不同运算符执行运算
-(NSString *)Execute{

    switch (self.exType) {
        case 1:
            self.result=[self getQuotient];
            break;
        case 2:
            self.result=[self getProduct];
            break;
        case 3:
            self.result=[self getDifference];
            break;
        case 4:
            self.result=[self getSum];
            break;
        default:
            break;
    }
    self.number1=self.result;
    self.number2=nil;
    
    return self.result;
}

//计算和
-(NSString *)getSum{
    double num1=[self.number1 doubleValue];
    double num2=[self.number2 doubleValue];
    return [NSString stringFloatHandle:[NSString stringWithFormat:@"%f",num1+num2]];
}
//计算差
-(NSString *)getDifference{
    double num1=[self.number1 doubleValue];
    double num2=[self.number2 doubleValue];
    return [NSString stringFloatHandle:[NSString stringWithFormat:@"%f",num1-num2]];

}
//计算积
-(NSString *)getProduct{
    double num1=[self.number1 doubleValue];
    double num2=[self.number2 doubleValue];
    return [NSString stringFloatHandle:[NSString stringWithFormat:@"%f",num1*num2]];

}
//计算商
-(NSString *)getQuotient{
    double num1=[self.number1 doubleValue];
    double num2=[self.number2 doubleValue];
    return [NSString stringFloatHandle:[NSString stringWithFormat:@"%f",num1/num2]];

}
//转换正负数
-(NSString *)getPlusMinus:(NSString *)number{
    double numberFloat=[number doubleValue];
    NSString *returnStr=number;
    numberFloat=0-numberFloat;
    returnStr=[NSString stringWithFormat:@"%f",numberFloat];
    return [NSString stringFloatHandle:returnStr];
}



//清空
-(void)calculatorEmpty{
    self.number1=nil;
    self.number2=nil;
    self.result=nil;
    self.exType=0;
}

@end
