Ejemplo n.º 1
0
 /// <summary>
 ///  processing a click on "equal" button where is the main choice of further operations and functions
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void equal_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Length > 0 && textBox2.Text.Length > 0) // textBox is not empty
     {
         if (textBox3.Text.Length == 0 || flag > 0)
         {
             textBox3.Text = textBox1.Text;
             secondNumber  = Convert.ToDouble(textBox3.Text);
             firstNumber   = Convert.ToDouble(textBox2.Text);
             ITwoArgCalculator calculator = TwoArgFactory.CreateCalculator(Operation);
             result = calculator.Calculate(firstNumber, secondNumber);
             def1();
         }
         else
         {
             textBox2.Text = textBox1.Text;
             secondNumber  = Convert.ToDouble(textBox3.Text);
             firstNumber   = Convert.ToDouble(textBox2.Text);
             ITwoArgCalculator calculator = TwoArgFactory.CreateCalculator(Operation);
             result = calculator.Calculate(firstNumber, secondNumber);
             def1();
         }
     }
     else
     {
         textBox1.Focus();
     }
     textBox1.Focus();
 }
Ejemplo n.º 2
0
        private void proc_Click(object sender, EventArgs e)
        {
            flag++;
            textBox3.Text = textBox1.Text + "%";
            secondNumber  = Convert.ToDouble(textBox1.Text);
            firstNumber   = Convert.ToDouble(textBox2.Text);
            ITwoArgCalculator calculator = TwoArgFactory.CreateCalculator("proc");

            result        = calculator.Calculate(firstNumber, secondNumber);
            textBox1.Text = Convert.ToString(result);
        }
        public ActionResult Index(
            double firstNumber,
            double secondNumber,
            string operation)
        {
            string[] arr = { "mult", "div", "plus", "minus" };
            double   result;

            if (arr.Contains(operation))
            {
                ITwoArgCalculator calculator = TwoArgFactory.CreateCalculator(operation);
                result = calculator.Calculate(firstNumber, secondNumber);
            }
            else
            {
                IOneArgCalculator calculator = OneArgFactory.CreateCalculator(operation);
                result = calculator.Calculate(firstNumber);
            }

            ViewBag.Result    = result;
            ViewBag.Operation = new SelectListItem[]
            {
                new SelectListItem()
                {
                    Value = "mult", Text = "multiply"
                },
                new SelectListItem()
                {
                    Value = "plus", Text = "sum"
                },
                new SelectListItem()
                {
                    Value = "minus", Text = "minus"
                },
                new SelectListItem()
                {
                    Value = "div", Text = "division"
                },
                new SelectListItem()
                {
                    Value = "sin", Text = "sin"
                },
                new SelectListItem()
                {
                    Value = "cos", Text = "cos"
                },
                new SelectListItem()
                {
                    Value = "tg", Text = "tg"
                },
                new SelectListItem()
                {
                    Value = "ctg", Text = "ctg"
                },
                new SelectListItem()
                {
                    Value = "sqrt", Text = "sqrt"
                }
            };
            return(View());
        }
Ejemplo n.º 4
0
        public void CalculateTest(string name, Type type)
        {
            var calculator = TwoArgFactory.CreateCalculator(name);

            Assert.IsInstanceOf(type, calculator);
        }