static void Main()
        {
            Dog sharo = new Dog(3, "Sharo", Sex.Female);
            Frog pesho = new Frog(9, "Pesho", Sex.Female);

            Animal[] animals = { sharo, pesho };

            Console.WriteLine(pesho.animalSound());

            Console.WriteLine(Animal.AverageAge(animals));
        }
        static void Main(string[] args)
        {
            Animal animal = new Cat("Mimi",4,Gender.female);
            Animal animal1 = new Dog("Sharo", 1, Gender.female);
            Animal animal2 = new Frog("Kikirica", 5, Gender.female);
            Animal animal3 = new Kitten("Mimi", 7);
            Animal animal4 = new Tomcat("Mimi", 5);
            Animal animal5 = new Frog("Mimi", 4, Gender.female);

            Animal[] zoo = new Animal[]{
            animal,animal1,animal2,animal3,animal4,animal
            };
            var avarageAge = zoo.Average(a=>a.Age);
            Console.WriteLine("{0:0.00}",avarageAge);
        }
示例#3
0
        static void Main()
        {
            Tomcat cat = new Tomcat("jonny", 4);
            Kitten cat2 = new Kitten("Holly", 2);
            Frog frog = new Frog("Jwey", 6, "male");
            Dog dog = new Dog("Sharo", 3, "male");
            cat.ProduceSound();
            cat2.ProduceSound();
            frog.ProduceSound();
            dog.ProduceSound();

            Animal[] animals = {
                cat, 
                cat2, 
                frog, 
                dog,
                new Dog("Polly", 12, "female"),
                new Frog("Kolio", 2, "male"),
                new Tomcat("Nuni", 3),
                new Kitten("Loly", 9),
                new Frog("Josh", 1, "male"),
                new Kitten("Jenny", 5),
                new Dog("Bond", 5, "male"),
                new Tomcat("Josh", 14)
            };

            var dogs = from animal in animals
                where animal is Dog
                select animal;

            var frogs = from animal in animals
                where animal is Frog
                select animal;

            var cats = from animal in animals
                where animal is Cat
                select animal;

            Console.WriteLine("Dogs avg age: " + ((double)dogs.Sum(a => a.Age)) / dogs.Count());

            Console.WriteLine("Frogs avg age: " + ((double)frogs.Sum(a => a.Age)) / frogs.Count());

            Console.WriteLine("Cats avg age: " + ((double)cats.Sum(a => a.Age)) / cats.Count());
        }
示例#4
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));
        }
示例#5
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));

        }
        static void Main()
        {
            Dog rex  = new Dog("Rex", 3, "male");
            Dog max  = new Dog("Max", 1, "male");
            Dog sara = new Dog("Sara", 6, "female");

            Frog frog   = new Frog("Frog", 7, "male");
            Frog jaba   = new Frog("Jaba", 4, "female");
            Frog kermit = new Frog("Kermit", 10, "male");

            Cat kitty    = new Kitten("Kitty", 2);
            Cat snowball = new Tomcat("Snowball", 5);

            List <Animal> animals = new List <Animal>()
            {
                rex,
                max,
                sara,
                frog,
                jaba,
                kermit,
                kitty,
                snowball
            };

            var groupedAnimals =
                from animal in animals
                group animal by animal.GetType().Name into g
                select new { GroupName = g.Key, AverageAge = g.ToList().Average(an => an.Age) };

            foreach (var animal in groupedAnimals)
            {
                Console.WriteLine("{0}s - average age: {1:N2}", animal.GroupName, animal.AverageAge);
            }

            rex.ProduceSound();
            kermit.ProduceSound();
            snowball.ProduceSound();
        }
示例#7
0
        static void Main(string[] args)
        {
            Dog dog = new Dog("sharo", AnimalSex.male, 18);
            Console.WriteLine(dog.ToString());

            Frog frog = new Frog("Kermit", AnimalSex.male, 20);
            Console.WriteLine(frog.ToString());

            Cat regularCat = new Cat("CAT", AnimalSex.female, 4);
            Console.WriteLine(regularCat.ToString());

            Kitten kitten = new Kitten("kittie", AnimalSex.female, 1);
            //Kitten kitten = new Kitten("kittie", AnimalSex.male, 1); - this will explode
            Console.WriteLine(kitten.ToString());

            Tomcat tomcat = new Tomcat("Topcat", AnimalSex.male, 2);
            //Tomcat tomcat = new Tomcat("Topcat", AnimalSex.female, 2); - this too will explode
            Console.WriteLine(tomcat.ToString());

            //sounds
            Console.WriteLine();
            Console.WriteLine(dog.ProduceSound());
            Console.WriteLine(frog.ProduceSound());
            Console.WriteLine(regularCat.ProduceSound());
            Console.WriteLine(kitten.ProduceSound());
            Console.WriteLine(tomcat.ProduceSound());
            Console.WriteLine();

            List<Dog> dogs = new List<Dog>();
            dogs.Add(dog);
            dogs.Add(new Dog("me4o", AnimalSex.female, 69));
            dogs.Add(new Dog("FU", AnimalSex.female, 96));
            double averageAge = dogs.Average((x) => x.Age);
            Console.WriteLine("Dogs average age: {0}", averageAge);

            List<Frog> frogs = new List<Frog>();
            frogs.Add(frog);
            frogs.Add(new Frog("Big Toad", AnimalSex.male, 2));
            frogs.Add(new Frog("Lesser Toad", AnimalSex.female, 2));
            averageAge = frogs.Average((x) => x.Age);
            Console.WriteLine("Frogs average age: {0}", averageAge);

            List<Kitten> kittens = new List<Kitten>();
            kittens.Add(kitten);
            kittens.Add(new Kitten("little kittenn", AnimalSex.female, 2));
            kittens.Add(new Kitten("big kitten", AnimalSex.female, 2));
            averageAge = kittens.Average((x) => x.Age);
            Console.WriteLine("Kittens average age: {0}", averageAge);
        }