Beispiel #1
0
        static void Main()
        {
            //some tests
            Dog d = new Dog("Joe", 4, Sex.male, FurColour.black);

            d.MakeSound();
            Console.WriteLine(d.GetSpecies());
            d.Bite();
            Console.WriteLine("----------------------");

            Kitten k = new Kitten("Kittie", 5, 10, 10);

            k.MakeSound();
            Console.WriteLine(k.GetSpecies());
            k.SayAge();
            k.Fight();
            Console.WriteLine("----------------------");

            Tomcat t = new Tomcat("Tommie", 3, 15, 25);

            Console.WriteLine(t.GetSpecies());
            t.SayAge();
            t.Fight();
            t.MakeSound();
            Console.WriteLine("----------------------");

            Frog f = new Frog("Froggy", 1, Sex.male, 3);

            Console.WriteLine(f.GetSpecies());
            Console.WriteLine("Froggy has {0} green spots", f.greenSpots);
            f.SayAge();
            f.MakeSound();
            Console.WriteLine("----------------------");

            //instantiate arrays of dogs and tomcats
            Dog[]    dogs    = InstantiateDogs();
            Tomcat[] tomcats = InstantiateTomcats();

            //calculate average age
            Console.WriteLine("Average age of dogs: {0}", Animal.CalcAverageAge(dogs));
            Console.WriteLine("Average age of tomcats: {0}", Animal.CalcAverageAge(tomcats));
        }
Beispiel #2
0
        static void Main()
        {
            Animal[] animals =
            {
                new Dog(5,    "Pesho",  true),
                new Dog(3,    "Ivan",   true),
                new Frog(2,   "Gosho",  true),
                new Frog(1,   "Sisi",   false),
                new Kitten(1, "Mimi",   false),
                new Kitten(6, "Gabi",   false),
                new Tomcat(2, "Ivan",   true),
                new Tomcat(4, "Toshko", true),
            };

            foreach (Animal animal in animals)
            {
                animal.ProduceSound();
            }

            Animal.CalcAverageAge(animals);
        }