Beispiel #1
0
        private double runAction()
        {
            switch (action)
            {
            case _DIVIDE:
                calculator.Divide(double.Parse(calcDisplay));
                calcDisplay = calculator.GetResult().ToString();
                base.OnPropertyChanged("Sum");
                break;

            case _MULTIPLY:
                try
                {
                    calculator.Multiply(double.Parse(calcDisplay));
                    calcDisplay = calculator.GetResult().ToString();
                    base.OnPropertyChanged("Sum");
                }
                catch (DivideByZeroException e)
                {
                    Models.Logging.append(e.Message, Models.Logging.ALL);
                }
                break;

            case _SUBTRACT:
                calculator.Subtract(double.Parse(calcDisplay));
                calcDisplay = calculator.GetResult().ToString();
                base.OnPropertyChanged("Sum");
                break;

            case _CLEAR:
                break;

            case _ADD:
            default:
                calculator.Add(double.Parse(calcDisplay));
                calcDisplay = calculator.GetResult().ToString();
                base.OnPropertyChanged("Sum");
                break;
            }
            return(calculator.GetResult());
        }
Beispiel #2
0
 private void MPlusMathCom()
 {
     memory.Add(double.Parse(calcDisplay));
 }
Beispiel #3
0
        public IActionResult Index(String Numbers = "", String Calculate = OtherAction)
        {
            int[] NumbersToSum;
            int   Sum;
            bool  Prime;

            ViewData["Message1"]  = "";
            ViewData["Message2"]  = "";
            ViewData["Message3"]  = "";
            ViewData["InputNums"] = "";
            ViewData["Result"]    = "";
            ViewData["ResultOut"] = "";

            switch (Calculate)
            {
            case AddAction:
                if (Numbers != null)
                {
                    try
                    {
                        NumbersToSum          = StringToNumbers(Numbers);
                        Sum                   = calculator.Add(NumbersToSum);
                        ViewData["Message1"]  = "Lukujen ";
                        ViewData["InputNums"] = Numbers;
                        ViewData["Message2"]  = " summa on ";
                        ViewData["Result"]    = Sum;
                        ViewData["ResultOut"] = Sum;
                        ViewData["Message3"]  = ".";
                    }
                    catch (FormatException fe)
                    {
                        ViewData["Message1"]  = ParseErrorStart;
                        ViewData["InputNums"] = Numbers;
                        ViewData["Message2"]  = ParseErrorEnd;
                        ViewData["Result"]    = ParseErrorResult;
                    }
                }
                else
                {
                    ViewData["Message1"] = EmptyMsg;
                    ViewData["Result"]   = EmptyResult;
                }
                break;

            case PrimeAction:
                if (Numbers != null)
                {
                    try
                    {
                        NumbersToSum = StringToNumbers(Numbers);
                        Sum          = calculator.Add(NumbersToSum);
                        Prime        = calculator.IsPrime(Sum);

                        if (Prime)
                        {
                            ViewData["Message1"]  = "Luku ";
                            ViewData["InputNums"] = Sum;
                            ViewData["Message2"]  = " on alkuluku.";
                            ViewData["Result"]    = Prime;
                        }
                        else
                        {
                            ViewData["Message1"]  = "Luku ";
                            ViewData["InputNums"] = Sum;
                            ViewData["Message2"]  = " ei ole alkuluku.";
                            ViewData["Result"]    = Prime;
                        }
                    }
                    catch (FormatException fe)
                    {
                        ViewData["Message1"]  = ParseErrorStart;
                        ViewData["InputNums"] = Numbers;
                        ViewData["Message2"]  = ParseErrorEnd;
                        ViewData["Result"]    = ParseErrorResult;
                    }
                }
                else
                {
                    ViewData["Message1"] = EmptyMsg;
                    ViewData["Result"]   = EmptyResult;
                }
                break;

            default:
                ViewData["Message1"] = "Kirjoita tutkittava luku tai luvut kenttään ja valitse haluamasi toiminto.";
                break;
            }
            return(View());
        }