static void Main(string[] args)
        {
            Mammals m = new Mammals();
            Console.WriteLine(m.Move());
            Console.WriteLine(m.Greet());
            m = new Cat();
            Console.WriteLine(m.Move());
            Console.WriteLine(m.Greet());
            m = new Dog();
            Console.WriteLine(m.Move());
            Console.WriteLine(m.Greet());

            Console.WriteLine();

            Reptiles r = new Reptiles();
            Console.WriteLine(r.Move());
            Console.WriteLine(r.Temperature());
            r = new Crocodile();
            Console.WriteLine(r.Move());
            Console.WriteLine(r.Temperature());

            Console.WriteLine();

            Birds b = new Birds();
            Console.WriteLine(b.Move());
            Console.WriteLine(b.MakeNest());
            b = new Owl();
            Console.WriteLine(b.Move());
            Console.WriteLine(b.MakeNest());

            Console.WriteLine();

            Fish f = new Fish();
            Console.WriteLine(f.Move());
            f = new Shark();
            Console.WriteLine(f.Move());

            Console.ReadKey();
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            var listOfAnimals = new List <Animal>();

            var animalType   = Console.ReadLine();
            var animalTokens = Console.ReadLine()
                               .Split(";", StringSplitOptions.RemoveEmptyEntries);

            while (true)
            {
                var    name = animalTokens[0];
                var    food = animalTokens[1];
                string gender;


                switch (animalType)
                {
                case "Dog":
                    try
                    {
                        if (animalTokens.Length > 2)
                        {
                            gender = animalTokens[2];
                            Dog dog = new Dog(name, food, gender);

                            Console.WriteLine(dog.ExplainMyselft());
                        }
                        else
                        {
                            Animal dog = new Dog(name, food);

                            Console.WriteLine(dog.ExplainMyselft());
                        }

                        Console.WriteLine("Animal added.");
                    }
                    catch (InvalidInputException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "Cat":
                    try
                    {
                        Animal cat = new Cat(name, food);

                        Console.WriteLine(cat.ExplainMyselft());
                        Console.WriteLine("Animal added.");
                    }
                    catch (InvalidInputException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "Fish":
                    try
                    {
                        Animal fish = new Fish(name, food);

                        Console.WriteLine(fish.ExplainMyselft());
                        Console.WriteLine("Animal added.");
                    }
                    catch (InvalidInputException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;
                }

                animalType = Console.ReadLine();

                if (animalType == "End")
                {
                    break;
                }

                animalTokens = Console.ReadLine()
                               .Split(";", StringSplitOptions.RemoveEmptyEntries);
            }
        }