public void Execute()
        {
            IMessagePrinter printer = uiFactory.CreateMessagePrinter();
            List <String>   args    = new List <string>();

            args.Add("Number");
            args.Add("Error");

            IDialogView   dialog  = uiFactory.CreateDialogView();
            List <string> results = dialog.ShowSelectionDialog(args);
            double        number  = 0;
            double        error   = 0;

            if (!double.TryParse(results.ElementAt(0), out number))
            {
                printer.Print("First input is not a number");
            }
            if (!double.TryParse(results.ElementAt(1), out error))
            {
                printer.Print("Second input is not a number");
            }
            ITaylorExpansion exp    = new ArctgExpansion(error, number);
            Result           result = exp.Calculate();

            printer.Print("Answer " + result.Answer);
        }
        public void ShowMenu()
        {
            IDialogView dialogView = uiFactory.CreateDialogView();

            dialogView.ShowMessage("MENU");
            IMenuView     menuView  = uiFactory.CreateMenuView();
            List <string> menuItems = commands.Keys.ToList();

            menuItems.Add("Exit");

            while (true)
            {
                string result       = menuView.ShowMenu(menuItems);
                int    parsedResult = -1;
                if (int.TryParse(result, out parsedResult))
                {
                    if (parsedResult <= commands.Count)
                    {
                        commandProcessor.Execute(commands.Values.ToList().ElementAt(parsedResult - 1));
                    }
                    else if (parsedResult == commands.Count + 1)
                    {
                        dialogView.ShowMessage("Exiting");
                        return;
                    }
                    else
                    {
                        dialogView.ShowMessage("No such menu item");
                    }
                }
            }
        }
Beispiel #3
0
        public void Execute()
        {
            IMessagePrinter printer = uiFactory.CreateMessagePrinter();
            List <String>   args    = new List <string>();

            args.Add("Error");
            args.Add("Number");
            args.Add("Power");
            IDialogView   dialog        = uiFactory.CreateDialogView();
            List <string> results       = dialog.ShowSelectionDialog(args);
            double        number        = 0;
            double        error         = 0;
            double        power         = 0;
            bool          parsingfailed = false;

            if (!double.TryParse(results.ElementAt(0), out error))
            {
                parsingfailed = true;
                printer.Print("First input is not a number");
            }
            if (!double.TryParse(results.ElementAt(1), out number))
            {
                parsingfailed = true;
                printer.Print("Second input is not a number");
            }
            if (!double.TryParse(results.ElementAt(1), out power))
            {
                parsingfailed = true;
                printer.Print("Third input is not a number");
            }
            if (!parsingfailed)
            {
                ITaylorExpansion exp    = new Power(error, number, power);
                Result           result = exp.Calculate();
                if (result.Exist)
                {
                    printer.Print("Answer " + result.Answer);
                }
                else
                {
                    printer.Print("Answer does not exist");
                }
            }
        }