示例#1
0
        static void Main(string[] args)
        {
            // a count that regulates what animal the program is on and what to print.
            int _count = 1;

            Console.WriteLine("For the Dog");
            while (_count < 3)
            {
                // asking the user what the name, height, weight, and color of each animal is
                Console.WriteLine("Name?");
                string _name = Console.ReadLine();

                double _height;
                Console.WriteLine("Height? (in)");
                string _inputHeight = Console.ReadLine();
                double.TryParse(_inputHeight, out _height);

                double _weight;
                Console.WriteLine("Weight? (oz)");
                string _inputWeight = Console.ReadLine();
                double.TryParse(_inputWeight, out _weight);

                string _color;
                Console.WriteLine("Color?");
                _color = Console.ReadLine();

                // if count = 1, then it's the dog's turn
                // the user's input is sent to the dog class
                // the info is printed out and one more is added for the count
                // "For the cat?" is printed out and the loop is re done.
                if (_count == 1)
                {
                    Dog    _dog      = new Dog(_name, _height, _weight, _color);
                    string _printOut = _dog.PrintOutDetails();
                    Console.WriteLine(_printOut);
                    _count++;

                    Console.WriteLine();
                    Console.WriteLine("For the cat?");
                    continue;
                }
                else if (_count == 2)
                {
                    Cat    _cat      = new Cat(_name, _height, _weight, _color);
                    string _printOut = _cat.PrintOutDetails();
                    Console.WriteLine(_printOut);
                    break;
                }
            }
        }