示例#1
0
        static void Main(string[] args)
        {
            string messForPerson = "Number is prime: Input 1 and 1 parameters\n" +
                                   "Distanse between Points: Input 2 and 4 parameters Point1(x1,y1) Point2(x2,y2)\n" +
                                   "Count number in Numeral: Input 3 and 1 parameters\n" +
                                   "Exit: Input 0";


            Dictionary <int, MathCommandAbstract> dicWithCommand = new Dictionary <int, MathCommandAbstract>();

            dicWithCommand.Add(1, new NumberInfo());
            dicWithCommand.Add(2, new PointsWorker());
            dicWithCommand.Add(3, new CounterNumberInNumeral());



            bool flagToExit = false;

            while (!flagToExit)
            {
                Console.WriteLine(messForPerson);
                int numberFlag = ConsoleWorker.getIntegerValue();

                if (numberFlag == 0)
                {
                    flagToExit = true; continue;
                }
                else
                {
                    MathCommandAbstract command = dicWithCommand[numberFlag];

                    List <int> parametersList = new List <int>();
                    //command.GetType().GetFields().Length <<== count of fields in class
                    for (int i = 0; i < command.GetType().GetFields().Length; i++)
                    {
                        int param = ConsoleWorker.getIntegerValue("Input Parameter: ");
                        parametersList.Add(param);
                    }


                    command.SetParams(parametersList.ToArray());
                    command.Execute();
                    Console.WriteLine();
                }
            }
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            string messForPerson = "Number is prime: Input 1\n" +
                                   "Distanse between Points: Input 2\n" +
                                   "Count number in Numeral: Input 3\n" +
                                   "Exit: Input 0";


            bool flagToExit = false;

            while (!flagToExit)
            {
                Console.WriteLine(messForPerson);
                int numberFlag = ConsoleWorker.getIntegerValue();
                MathCommandAbstract command = null;
                IBaseRecirver       recirver;
                if (numberFlag == 0)
                {
                    flagToExit = true; continue;
                }
                switch (numberFlag)
                {
                case 1:
                    recirver = new NumberInfoRecirver(ConsoleWorker.getIntegerValue("Input number "));
                    command  = new NumberInfo((NumberInfoRecirver)recirver);
                    break;

                case 2:
                    recirver = new PointRecirver(ConsoleWorker.getIntegerValue("Input x1 "),
                                                 ConsoleWorker.getIntegerValue("Input y1 "),
                                                 ConsoleWorker.getIntegerValue("Input x2 "),
                                                 ConsoleWorker.getIntegerValue("Input y2 "));
                    command = new PointsWorker((PointRecirver)recirver);
                    break;

                case 3:
                    recirver = new CounterNumberInNumeralRecirver(ConsoleWorker.getIntegerValue("Input number "));
                    command  = new CounterNumberInNumeral((CounterNumberInNumeralRecirver)recirver);
                    break;
                }
                command.Execute();
                Console.WriteLine();
            }

            Console.ReadLine();
        }