Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //This program instantiates a class of each type and runs the various tests.

            OOValidator num  = new OOValidator();
            MyValidator word = new MyValidator();

            Console.WriteLine("Welcome to the Validation Tester Application!");
            Console.WriteLine("\nInt Test");
            num.getIntWithinRange("", -100, 100);
            Console.WriteLine("\nDouble Test");
            num.getDoubleWithinRange("", -100, 100);
            Console.WriteLine("\nString Test");
            word.GetRequiredString("word");
            word.GetChoiceString("", "and", "but");
            Console.ReadLine();
        }
        //For the user to proceed, he or she must enter a number within the specified range.

        public double getDoubleWithinRange(string prompt, double min, double max)
        {
            bool        run = true;
            OOValidator num = new OOValidator();

            while (run)
            {
                Console.WriteLine("Enter a double between -100 and 100: ");
                _myDouble = num.getDouble(Console.ReadLine());
                if (_myDouble < min)
                {
                    Console.WriteLine("Error! Number must be greater than " + (min - 1));
                }
                else if (_myDouble > max)
                {
                    Console.WriteLine("Error! Number must be less than " + (max + 1));
                }
                else
                {
                    run = false;
                }
            }
            return(_myDouble);
        }
        //For the user to proceed, he or she must enter an integer within the specified range.

        public int getIntWithinRange(string prompt, int min, int max)
        {
            bool        run = true;
            OOValidator num = new OOValidator();

            while (run)
            {
                Console.WriteLine("Enter an integer between -100 and 100: ");
                _myInt = num.getInt(Console.ReadLine());
                if (_myInt < min)
                {
                    Console.WriteLine("Error! Number must be greater than " + (min - 1));
                }
                else if (_myInt > max)
                {
                    Console.WriteLine("Error! Number must be less than " + (max + 1));
                }
                else
                {
                    run = false;
                }
            }
            return(_myInt);
        }