Example #1
0
        public override int Evaluate(EvaluateOption option, Calculator calculator)
        {
            VerifyEvaluationState();

            int result = 0;

            switch (option)
            {
            case EvaluateOption.UIEvaluate:

                calculator.Clear();
                int leftValue = Left.Evaluate(option, calculator);

                calculator.Clear();
                int rightValue = Right.Evaluate(option, calculator);

                calculator.Clear();

                calculator.Result = leftValue;

                InvokeOperator(calculator);

                calculator.Result = rightValue;

                calculator.Evaluate();

                result = int.Parse(calculator.Result.ToString());

                break;

            case EvaluateOption.ActualEvaluate:
                result = Evaluate(Left.Evaluate(option, calculator), Right.Evaluate(option, calculator));
                break;
            }

            return(result);
        }
Example #2
0
        public override int Evaluate(EvaluateOption option, Calculator calculator)
        {
            if (Operand == null)
            {
                throw new InvalidOperationException();
            }

            int result = 0;

            switch (option)
            {
            case EvaluateOption.UIEvaluate:

                calculator.Clear();

                int operandEval = Operand.Evaluate(option, calculator);

                calculator.Clear();

                calculator.Result = operandEval;

                InvokeOperator(calculator);

                calculator.Evaluate();

                result = int.Parse(calculator.Result.ToString());

                break;

            case EvaluateOption.ActualEvaluate:
                result = Evaluate(Operand.Evaluate(option, calculator));
                break;
            }

            return(result);
        }
Example #3
0
 public abstract int Evaluate(EvaluateOption option, Calculator calculator);
Example #4
0
 public override int Evaluate(EvaluateOption option, Calculator calculator)
 {
     return(_number);
 }