示例#1
0
        public Calculator ReturnObject(string operand)
        {
            Calculator calculator = null;

            if (operand == "+" || operand == "-" || operand == "/" || operand == "*")
            {
                switch (operand)
                {
                case "+":
                    Addition addition = new Addition();
                    return(calculator = addition);

                case "-":
                    Substraction substraction = new Substraction();
                    return(calculator = substraction);

                case "*":
                    Multiplication multiplication = new Multiplication();
                    return(calculator = multiplication);

                case "/":
                    Division division = new Division();
                    return(calculator = division);
                }
            }
            return(calculator);
        }
示例#2
0
        // Menghitung hasil operasi <operand1> <operator> <operand2>
        public double calculate()
        {
            Expression temp = new TerminalExpression(0);

            switch (operatorSign)
            {
            case "+":
                temp = new Addition(operand1, operand2);
                break;

            case "-":
                temp = new Substraction(operand1, operand2);
                break;

            case "*":
                temp = new Multiplication(operand1, operand2);
                break;

            case "/":
                temp = new Division(operand1, operand2);
                break;

            case "^":
                temp = new Power(operand1, operand2);
                break;

            case "sqrt":
                temp = new SquareRoot(operand1);
                break;

            case "mod":
                temp = new Modulus(operand1, operand2);
                break;
            }
            return(temp.solve());
        }