public static Operation CreateOperation(string op) { Operation oper = null; switch (op.ToLower()) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "/": oper = new OperationDiv(); break; case "*": oper = new OperationMul(); break; default: break; } return(oper); }
public static Operation createOperate(string operate) { Operation oper = null; // 这就是多态的实现吧 switch (operate) { case "+": { oper = new OperationAdd(); break; } case "-": { oper = new OperationSub(); break; } case "*": { oper = new OperationMul(); break; } case "/": { oper = new OperationDiv(); break; } } return(oper); }
public static Operation CreateOperate(string operate) { Operation oper = null; switch (operate) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "*": oper = new OperationMul(); break; case "/": oper = new OperationDiv(); break; } return(oper); }
public static Operation createOperate(string operate) { Operation opera = null; switch (operate) { case "+": { opera = new OperationAdd(); } break; case "-": { opera = new OperationSub(); } break; case "*": { opera = new OperationMul(); } break; case "/": { opera = new OperationDiv(); } break; default: break; } return(opera); }
public static Operation CreateOperate(OperationType type) { Operation oper = null; switch (type) { case OperationType.ADD: oper = new OperationAdd(); break; case OperationType.SUB: oper = new OperationSub(); break; case OperationType.MUL: oper = new OperationMul(); break; case OperationType.DIV: oper = new OperationDiv(); break; } return(oper); }
public void GetResultTest(double numberA, double numberB, double result) { OperationDiv div = new OperationDiv(); div.NumberA = numberA; div.NumberB = numberB; Assert.Equal(div.GetResult(), result); }
private void Button_Click_1(object sender, RoutedEventArgs e) { try { double num1 = 0; double num2 = 0; Operator _OP = null; if (!double.TryParse(TB_Number1.Text, out num1)) { MessageBox.Show("Input Error Number1 :" + TB_Number1.Text, "錯誤"); return; } if (!double.TryParse(TB_Number2.Text, out num2)) { MessageBox.Show("Input Error Number2 :" + TB_Number2.Text, "錯誤"); return; } string _Operators = Operators.Text; if (_Operators.Trim() == "") { MessageBox.Show("Select Error Operators :" + Operators.Text, "錯誤"); return; } else { if (_Operators == "+") { _OP = new OperationAdd(); } else if (_Operators == "-") { _OP = new OperationSub(); } else if (_Operators == "*") { _OP = new OperationMul(); } else if (_Operators == "/") { _OP = new OperationDiv(); } } _OP.NumberA = num1; _OP.NumberB = num2; double result = _OP.GetResult(); Result_Cal.Text = result.ToString(); } catch (Exception ex) { MessageBox.Show("The ex is: " + ex.ToString()); } }
public static Operation createOperate(string operate) { Operation oper = null; if (operate == "+"){ oper = new OperationAdd(); } else if (operate == "-"){ oper = new OperationSub(); } else if (operate == "*"){ oper = new OperationMul(); } else if (operate == "/"){ oper = new OperationDiv(); } return oper; }
public static Operation CreationOperation(string operate) { Operation oper = null; switch (operate) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "*": oper = new OperationMul(); break; case "/": oper = new OperationDiv(); break; } return oper; }
public static Operation createOperation(string operation) { Operation oper = null; switch (operation) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "*": oper = new OperationMul(); break; case "/": oper = new OperationDiv(); break; case "SquareRoot": oper = new OperationSquareRoot(); break; case ".": oper = new OperationPoint(); break; case "+/-": oper = new OperationPosAndNeg(); break; default: break; } return(oper); }
public static Operation createOperate(string operate) { Operation oper = null; if (operate == "+") { oper = new OperationAdd(); } else if (operate == "-") { oper = new OperationSub(); } else if (operate == "*") { oper = new OperationMul(); } else if (operate == "/") { oper = new OperationDiv(); } return(oper); }
public static Operation createOperator(string inputOperator) { Operation oper = null; switch (inputOperator) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "*": oper = new OperationMul(); break; case "/": oper = new OperationDiv(); break; } return(oper); }