Inheritance: Cat, ISound
Exemplo n.º 1
3
        public static void Main()
        {
            Cat[] cats = new Cat[]
            {
                new Cat("Pussi", 3, false),
                new Cat("Pesho", 6, true),
                new Cat("Ginka", 7, false),
            };
            Dog[] dogs = new Dog[]
            {
                new Dog("Misho", 5, true, "Ovcharka"),
                new Dog("Bull", 6, true, "Buldog"),
                new Dog("Rocko", 7, true, "Sharpei"),
            };
            Frog[] frogs = new Frog[]
            {
                new Frog("Furi", 2, true),
                new Frog("Mani", 3, false),
                new Frog("Perr", 2, false),
            };
            Kitten[] kittens = new Kitten[]
            {
                new Kitten("Stupi", 1, "Persian"),
                new Kitten("Lili", 1, "Persian"),
                new Kitten("Plupi", 2, "Angora"),
            };
            Tomcat[] tomcats = new Tomcat[]
            {
                new Tomcat("Gunko", 4),
                new Tomcat("Porfavor", 3),
                new Tomcat("Kalin", 5),
            };

            double dogsAvAge = Animal.AverageAge(dogs);
            double catsAvAge = Animal.AverageAge(cats);
            double frogsAvAge = Animal.AverageAge(frogs);
            double kittensAvAge = Animal.AverageAge(kittens);
            double tomcatsAvAge = Animal.AverageAge(tomcats);

            Console.WriteLine("Average age: \nDogs: {0:F1};\nCats: {1:F1};\nFrogs: {2:F1};\nKittens: {3:F1};\nTomcats: {4:F1};",
                dogsAvAge, catsAvAge, frogsAvAge, kittensAvAge, tomcatsAvAge);
            Console.WriteLine();

            Console.WriteLine("Different animals sounds:");
            Console.Write("Cats: ");
            cats[0].ProduceSound();
            Console.Write("Dogs: ");
            dogs[1].ProduceSound();
            Console.Write("Frogs: ");
            frogs[2].ProduceSound();
            Console.WriteLine();

            Console.WriteLine("Different animals character activities:");
            Console.WriteLine(dogs[2].SpinTail());
            Console.WriteLine(cats[1].Tease());
            Console.WriteLine(frogs[2].Jump());
        }
Exemplo n.º 2
0
        static void Main()
        {
            // Attention! - No animals were harmed during these tests

            Console.Title = "Animals";

            var dog = new Dog("Gosho", 3, Gender.Male);

            Console.WriteLine(dog);
            dog.FetchStick();
            Console.Write(Environment.NewLine);

            var frog = new Frog("Masha", 16, Gender.Female);

            Console.WriteLine(frog);
            frog.Transform();
            Console.Write(Environment.NewLine);

            var kitty = new Kitten("Maca", 0);

            Console.WriteLine(kitty);
            kitty.MeltYourHeart();
            Console.Write(Environment.NewLine);

            var tomcat = new Tomcat("Tom", 4);

            Console.WriteLine(tomcat);
            tomcat.Piss();
            Console.Write(Environment.NewLine);

            var animals = new Animal[]
            {
                new Dog("Freya", 1, Gender.Female),
                new Dog("Sharo", 4, Gender.Male),
                new Frog("Penka", 20, Gender.Female),
                new Frog("Fred", 32, Gender.Male),
                new Kitten("Merlin", 1),
                new Kitten("Shusia", 0),
                new Tomcat("Felix", 6),
                new Tomcat("Silvester", 5),
            };

            var averageAge = from an in animals
                             group an by new
            {
                GroupName = an.GetType().Name
            }
            into gender select new
            {
                gender.Key.GroupName,
                AvarageAge = gender.Average(an => an.Age)
            };

            foreach (var animal in averageAge)
            {
                Console.WriteLine(String.Format("Group: {0}, AvarageAge: {1:0.00}.", animal.GroupName, animal.AvarageAge));
            }

            // And what does the Fox say? Oh, no foxes here...
        }
Exemplo n.º 3
0
        static void Main()
        {
            var scooby = new Dog("Scooby", 2, 'm');
            var frogy = new Frog("Frogy", 0.5, 'm');
            var tommy = new Cat("Tommy", 1, 'm');
            var kitty = new Kitten("Kitty", 0.8, 'f');
            var speedy = new Tomcat("Speedy", 1.5, 'f');
            var spark = new Dog("Spark", 3, 'm');
            var carmit = new Frog("Carmit", 1, 'm');
            var jenny = new Kitten("Jenny", 1.2, 'f');

            var animals = new Animal[] { scooby, spark, frogy, tommy, kitty, speedy };
            var differentAnimals = new Animal[] { tommy, kitty, carmit, jenny };

            foreach (var animal in animals)
            {
                Console.Write(animal);
                animal.ProduceSound();
                Console.WriteLine();
            }

            var groupedAnimals =
                from anim in animals
                group anim by (anim is Cat) ? typeof (Cat) : anim.GetType()
                into g
                select new {GroupName = g.Key, AverageAge = g.ToList().Average(an => an.Age)};

            foreach (var animal in groupedAnimals)
            {
                Console.WriteLine("{0} - average age: {1:N2}", animal.GroupName.Name, animal.AverageAge);
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            var jaba     = new Frog("baba jaba", 1, Genders.Female);
            var kekerica = new Frog("kekerica", 3, Genders.Female);

            var sharo = new Dog("sharo", 3, Genders.Male);
            var sara  = new Dog("sara", 2, Genders.Female);
            var oldy  = new Dog("oldy", 12, Genders.Male);

            var puhi        = new Kitten("puhi", 2);
            var tommy       = new Tomcat("tommy", 4);
            var mouseKiller = new Cat("mousy", 5, Genders.Male);

            var animals = new List <Animal>()
            {
                jaba,
                kekerica,
                sharo,
                sara,
                puhi,
                tommy,
                mouseKiller,
                oldy
            };

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

            foreach (var animal in avredgeAgeOfKinds)
            {
                Console.WriteLine("{0} - average age: {1:N2}", animal.GroupName, animal.AverageAge);
            }
        }
Exemplo n.º 5
0
        private Animal GetAnimal(string animalType, string[] animalInformation)
        {
            string name   = animalInformation[0];
            int    age    = int.Parse(animalInformation[1]);
            string gender = GetGender(animalInformation);

            Animal animal = null;

            if (animalType == "Dog")
            {
                animal = new Dog(name, age, gender);
            }
            else if (animalType == "Frog")
            {
                animal = new Frog(name, age, gender);
            }
            else if (animalType == "Cat")
            {
                animal = new Cat(name, age, gender);
            }
            else if (animalType == "Kitten")
            {
                animal = new Kitten(name, age);
            }
            else if (animalType == "Tomcat")
            {
                animal = new Tomcat(name, age);
            }
            else
            {
                throw new ArgumentException("Invalid input");
            }
            return(animal);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Frog[] frogs = new Frog[5];
            frogs[0] = new Frog("Kermit", 5, 'M');
            frogs[1] = new Frog("Piggy", 8, 'F');
            frogs[2] = new Frog("Cookie Monster", 3, 'F');
            frogs[3] = new Frog("Oscar the grouch", 15, 'M');
            frogs[4] = new Frog("Kermit's double", 5, 'M');

            Dog[] dogs = new Dog[5];
            dogs[0] = new Dog("Rex", 1, 'M');
            dogs[1] = new Dog("Sergeant Dirty", 6, 'F');
            dogs[2] = new Dog("Lucky", 7, 'F');
            dogs[3] = new Dog("Unlucky", 2, 'M');
            dogs[4] = new Dog("Tramp", 4, 'M');

            Cat[] cats = new Cat[5];
            cats[0] = new Cat("Tom", 6, 'M');
            cats[1] = new Kitten("Princess", 1);
            cats[2] = new Cat("Jerry", 2, 'F');
            cats[3] = new Tomcat("Behemoth", 1);
            cats[4] = new Cat("Pluto", 7, 'M');

            Console.WriteLine("The average age of the frogs is " + Animal.AverageAge(frogs));
            Console.WriteLine("The average age of the dogs is " + Animal.AverageAge(dogs));
            Console.WriteLine("The average age of the cats is " + Animal.AverageAge(cats));
        }
Exemplo n.º 7
0
        private static string CreateNewSpecificAnimal(string type)
        {
            switch (type)
            {
            case "Cat":
                Cat cat = new Cat(animalName, animalAge, animalGender);
                return(cat.ToString());

            case "Dog":
                Dog dog = new Dog(animalName, animalAge, animalGender);
                return(dog.ToString());

            case "Frog":
                Frog frog = new Frog(animalName, animalAge, animalGender);
                return(frog.ToString());

            case "Kitten":
                Kitten kitten = new Kitten(animalName, animalAge);
                return(kitten.ToString());

            case "Tomcat":
                Tomcat tomcat = new Tomcat(animalName, animalAge);
                return(tomcat.ToString());

            default:
                return(null);
            }
        }
Exemplo n.º 8
0
        static void Main()
        {
            Dog dogNinja = new Dog("Stamat", 6, Sex.Male);
            dogNinja.Sound();

            Kitten kotence = new Kitten("Eli", 1, Sex.Female);

            // This will throw exeption
            // Kitten kotence = new Kitten("Eli", 1, Sex.Male);

            List<Animal> animalList = new List<Animal>();
            animalList.Add(new Frog("Stamat", 2, Sex.Male));
            animalList.Add(new Tomcat("Stamat", 1, Sex.Male));
            animalList.Add(new Dog("Stamat", 3, Sex.Male));
            animalList.Add(new Kitten("Stamat", 5, Sex.Female));
            animalList.Add(new Frog("Stamat", 7, Sex.Male));
            animalList.Add(new Tomcat("Stamat", 12, Sex.Male));
            animalList.Add(new Dog("Stamat", 65, Sex.Male));
            animalList.Add(new Kitten("Stamat", 47, Sex.Female));
            animalList.Add(new Frog("Stamat", 12, Sex.Male));
            animalList.Add(new Tomcat("Stamat", 36, Sex.Male));
            animalList.Add(new Dog("Stamat", 48, Sex.Male));
            animalList.Add(new Kitten("Stamat", 16, Sex.Female));
            animalList.Add(new Frog("Stamat", 42, Sex.Male));
            animalList.Add(new Tomcat("Stamat", 36, Sex.Male));
            animalList.Add(new Dog("Stamat", 71, Sex.Male));
            animalList.Add(new Kitten("Stamat", 30, Sex.Female));

            int averageAge = Animal.AverageAge(animalList);
            Console.WriteLine("The average age of all animals is: {0}", averageAge);
            
        }
Exemplo n.º 9
0
        public static void Main()
        {
            var animals = new List<Animal>();

            var kitten = new Kitten("Kitty", 2);

            SayAngAddToList(kitten, animals);

            var tomcat = new Tomcat("Tom", 1);

            SayAngAddToList(tomcat, animals);

            var frog = new Frog("Froggy", 5, Sex.Male);

            SayAngAddToList(frog, animals);

            var dog = new Dog("Sharo", 4, Sex.Male);

            SayAngAddToList(dog, animals);

            var anotherDog = new Dog("Lassy", 7, Sex.Female);

            SayAngAddToList(anotherDog, animals);

            Console.WriteLine("The average age of all animal is {0}", animals.Average(x => x.Age));
        }
Exemplo n.º 10
0
        public static void Main(string[] args)
        {
            var jaba = new Frog("baba jaba", 1, Genders.Female);
            var kekerica = new Frog("kekerica", 3, Genders.Female);

            var sharo = new Dog("sharo", 3, Genders.Male);
            var sara = new Dog("sara", 2, Genders.Female);
            var oldy = new Dog("oldy", 12, Genders.Male);

            var puhi = new Kitten("puhi", 2);
            var tommy = new Tomcat("tommy", 4);
            var mouseKiller = new Cat("mousy", 5, Genders.Male);

            var animals = new List<Animal>()
            {
                jaba, 
                kekerica,
                sharo,
                sara,
                puhi,
                tommy,
                mouseKiller,
                oldy
            };
            
            var avredgeAgeOfKinds = from a in animals
                                    group a by a.GetType().Name into g
                                    select new { GroupName = g.Key, AverageAge = g.ToList().Average(an => an.Age) };
            foreach (var animal in avredgeAgeOfKinds)
            {
                Console.WriteLine("{0} - average age: {1:N2}", animal.GroupName, animal.AverageAge);
            }
        }
Exemplo n.º 11
0
        static void Main()
        {
            Animal max = new Dog("Max", 3, Gender.Male);
            Animal duke = new Dog("Duke", 1, Gender.Male);
            Animal fluffy = new Dog("Fluffy", 6, Gender.Male);
            Animal wink = new Dog("Wink", 3, Gender.Male);
            Animal abby = new Frog("Abby", 1, Gender.Female);
            Animal boogy = new Frog("Boogy", 2, Gender.Male);
            Animal pookie = new Frog("Pookie", 6, Gender.Female);
            Animal hermit = new Frog("Hermit", 2, Gender.Male);
            Animal abbey = new Kitten("Abbey", 1, Gender.Female);
            Animal panda = new Kitten("Panda", 1, Gender.Female);
            Animal ravi = new Tomcat("Ravi", 3, Gender.Male);
            Animal lexus = new Tomcat("Lexus", 9, Gender.Male);
            Animal biggie = new Cat("Biggie", 7, Gender.Male);
            Animal fig = new Cat("Fig", 7, Gender.Male);

            Animal[] animals = new Animal[] { max, duke, fluffy, wink, abby, boogy, pookie, hermit, abbey, panda, ravi, lexus, biggie, fig };

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

            foreach (var animal in groupedAnimals)
            {
                Console.WriteLine("Group: {0} | Average Age: {1:F2}", animal.GroupName, animal.AverageAge);
            }
        }
Exemplo n.º 12
0
        static void Main()
        {
            // create some animals from each class and print them
            Dog dog = new Dog("Sharo", 3, Gender.Male);
            Console.WriteLine(dog);
            dog.FetchStick();

            Console.WriteLine();

            Frog frog = new Frog("Kermit", 33, Gender.Male);
            Console.WriteLine(frog);
            frog.Jump();

            Console.WriteLine();

            Kitten kitty = new Kitten("Kitty", 1);
            Console.WriteLine(kitty);
            kitty.Cry();

            Console.WriteLine();

            Tomcat tomcat = new Tomcat("Tom", 12);
            Console.WriteLine(tomcat);
            tomcat.Piss();

            Console.WriteLine();

            // create an array of Animals
            Animal[] animals = new Animal[]
            {
                new Dog("Rex",3, Gender.Male),
                new Frog("Kekerica", 1, Gender.Female),
                new Kitten("Pisi", 1),
                new Tomcat("Tom",2),
                new Dog("Erik", 4, Gender.Male),
                new Frog("Penka", 1, Gender.Female),
                new Kitten("Jasmin", 2),
                new Tomcat("Kolio",6),
                new Dog("Bender",2, Gender.Male),
                new Frog("Ginka", 6, Gender.Female),
                new Kitten("Tedy", 1),
                new Tomcat("Muncho",4),
            };

            // calculate the aveage age of each animal and print them 
            var averageAge =
                from an in animals
                group an by new { GroupName = an.GetType().Name } into gr
                select new
                {
                    GroupName = gr.Key.GroupName,
                    AvarageAge = gr.Average(an => an.Age)
                };

            foreach (var animal in averageAge)
            {
                Console.WriteLine(String.Format("Group: {0}, AvarageAge: {1:0.00}.", animal.GroupName, animal.AvarageAge));
            }
        }
Exemplo n.º 13
0
        public void Run()
        {
            string animalType = Console.ReadLine();

            while (animalType != "Beast!")
            {
                try
                {
                    string[] animalArgs = Console.ReadLine().Split();

                    string name   = animalArgs[0];
                    int    age    = int.Parse(animalArgs[1]);
                    string gender = animalArgs[2];

                    switch (animalType)
                    {
                    case "Cat":
                        Cat cat = new Cat(name, age, gender);
                        animals.Add(cat);
                        break;

                    case "Dog":
                        Dog dog = new Dog(name, age, gender);
                        animals.Add(dog);
                        break;

                    case "Frog":
                        Frog frog = new Frog(name, age, gender);
                        animals.Add(frog);
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(name, age);
                        animals.Add(kitten);
                        break;

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(name, age);
                        animals.Add(tomcat);
                        break;

                    default:
                        Console.WriteLine("Invalid input!");
                        break;
                    }
                }
                catch (InvalidInputException exception)
                {
                    Console.WriteLine(exception.Message);
                }

                animalType = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    string animalType = Console.ReadLine();
                    if (animalType == "Beast!")
                    {
                        break;
                    }
                    string[] animalArgs = Console.ReadLine().Split();
                    switch (animalType)
                    {
                    case "Dog":
                        Dog dog = new Dog(animalArgs);
                        dog.GetTypeOfAnimal();
                        Console.WriteLine(dog.ToString());
                        dog.ProduceSound();
                        break;

                    case "Cat":
                        Cat cat = new Cat(animalArgs);
                        cat.GetTypeOfAnimal();
                        Console.WriteLine(cat.ToString());
                        cat.ProduceSound();
                        break;

                    case "Frog":
                        Frog frog = new Frog(animalArgs);
                        frog.GetTypeOfAnimal();
                        Console.WriteLine(frog.ToString());
                        frog.ProduceSound();
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(animalArgs);
                        kitten.GetTypeOfAnimal();
                        Console.WriteLine(kitten.ToString());
                        kitten.ProduceSound();
                        break;

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(animalArgs);
                        tomcat.GetTypeOfAnimal();
                        Console.WriteLine(tomcat.ToString());
                        tomcat.ProduceSound();
                        break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        public static void Main()
        {
            List <Animal> animals = new List <Animal>();

            while (true)
            {
                string firstLine = Console.ReadLine();

                if (firstLine == "Beast!")
                {
                    break;
                }

                string[] secondLineTokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                // Spravka tuk: https://softuni.bg/forum/15928/problem-s-06-animals-ot-oop-basics-inheritance
                try
                {
                    switch (firstLine)
                    {
                    case "Dog":
                        var dog = new Dog(secondLineTokens[0], int.Parse(secondLineTokens[1]), secondLineTokens[2]);
                        animals.Add(dog);
                        break;

                    case "Frog":
                        var frog = new Frog(secondLineTokens[0], int.Parse(secondLineTokens[1]), secondLineTokens[2]);
                        animals.Add(frog);
                        break;

                    case "Cat":
                        var cat = new Cat(secondLineTokens[0], int.Parse(secondLineTokens[1]), secondLineTokens[2]);
                        animals.Add(cat);
                        break;

                    case "Kitten":
                        var kitten = new Kitten(secondLineTokens[0], int.Parse(secondLineTokens[1]));
                        animals.Add(kitten);
                        break;

                    case "Tomcat":
                        var tomcat = new Tomcat(secondLineTokens[0], int.Parse(secondLineTokens[1]));
                        animals.Add(tomcat);
                        break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            //Animal f = new Cat("F", 10, "M");
            //Console.WriteLine(f);
            //f.produceSound();

            string input = Console.ReadLine();

            while (input != "Beast!")
            {
                try
                {
                    string   animalType = input;
                    string[] animalArgs = Console.ReadLine().Split(' ');
                    string   name       = animalArgs[0];
                    int      age        = int.Parse(animalArgs[1]);
                    string   gender     = animalArgs[2];
                    string   nameSpace  = "Animals";

                    switch (animalType)
                    {
                    case "Cat":
                        Animal cat = new Cat(name, age, gender);
                        Console.WriteLine(cat);
                        cat.produceSound();
                        break;

                    case "Dog":
                        Animal dog = new Dog(name, age, gender);
                        Console.WriteLine(dog);
                        dog.produceSound();
                        break;

                    case "Frog":
                        Animal frog = new Frog(name, age, gender);
                        Console.WriteLine(frog);
                        frog.produceSound();
                        break;

                    case "Kitten":
                        Animal kitten = new Kitten(name, age, gender);
                        Console.WriteLine(kitten);
                        kitten.produceSound();
                        break;

                    case "Tomcat":
                        Animal tomcat = new Tomcat(name, age, gender);
                        Console.WriteLine(tomcat);
                        tomcat.produceSound();
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                input = Console.ReadLine();
            }
        }
Exemplo n.º 17
0
        public void Run()
        {
            string animalType = Console.ReadLine();

            while ((animalType = Console.ReadLine()) != "Beast!")
            {
                string[] animalInfo = Console.ReadLine()
                                      .Split(" ");

                Animal animal;

                try
                {
                    string name   = animalInfo[0];
                    int    age    = int.Parse(animalInfo[1]);
                    string gender = null;
                    gender = GetGender(animalInfo, gender);

                    animal = null;

                    if (animalType == "Cat")
                    {
                        animal = new Cat(name, age, gender);
                    }
                    else if (animalType == "Dog")
                    {
                        animal = new Dog(name, age, gender);
                    }
                    else if (animalType == "Frog")
                    {
                        animal = new Frog(name, age, gender);
                    }
                    else if (animalType == "Kitten")
                    {
                        animal = new Kitten(name, age);
                    }
                    else if (animalType == "Tomcat")
                    {
                        animal = new Tomcat(name, age);
                    }
                    else
                    {
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }

                this.animals.Add(animal);
            }

            foreach (Animal animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
        static void Main(string[] args)
        {
            while (true)
            {
                string comand = Console.ReadLine();

                if (comand == "Beast!")
                {
                    break;
                }

                string[] input  = Console.ReadLine().Split();
                string   name   = input[0];
                int      age    = int.Parse(input[1]);
                string   gender = input[2];

                if (string.IsNullOrEmpty(name) || age < 0 || string.IsNullOrEmpty(gender))
                {
                    Console.WriteLine("Invalid input!");
                    continue;
                }

                if (comand == "Cat")
                {
                    Cat cat = new Cat(name, age, gender);
                    Console.WriteLine(cat);
                    Console.WriteLine(cat.ProduceSound());
                }

                if (comand == "Dog")
                {
                    Dog dog = new Dog(name, age, gender);
                    Console.WriteLine(dog);
                    Console.WriteLine(dog.ProduceSound());
                }

                if (comand == "Frog")
                {
                    Frog frog = new Frog(name, age, gender);
                    Console.WriteLine(frog);
                    Console.WriteLine(frog.ProduceSound());
                }

                if (comand == "Kitten")
                {
                    Kitten kitten = new Kitten(name, age);
                    Console.WriteLine(kitten);
                    Console.WriteLine(kitten.ProduceSound());
                }

                if (comand == "Tomcat")
                {
                    Tomcat tomcat = new Tomcat(name, age);
                    Console.WriteLine(tomcat);
                    Console.WriteLine(tomcat.ProduceSound());
                }
            }
        }
Exemplo n.º 19
0
        public void Run()
        {
            while (true)
            {
                try
                {
                    string animalType = Console.ReadLine();

                    if (animalType == "Beast!")
                    {
                        break;
                    }

                    string[] animalInfo = Console.ReadLine()
                                          .Split()
                                          .ToArray();

                    string animalName   = animalInfo[0];
                    int    animalAge    = int.Parse(animalInfo[1]);
                    string animalGender = animalInfo[2];

                    if (animalType == "Dog")
                    {
                        var dog = new Dog(animalName, animalAge, animalGender);
                        Console.WriteLine(dog);
                    }

                    else if (animalType == "Frog")
                    {
                        var frog = new Frog(animalName, animalAge, animalGender);
                        Console.WriteLine(frog);
                    }

                    else if (animalType == "Cat")
                    {
                        var cat = new Cat(animalName, animalAge, animalGender);
                        Console.WriteLine(cat);
                    }

                    else if (animalType == "Kitten")
                    {
                        var kitten = new Kitten(animalName, animalAge);
                        Console.WriteLine(kitten);
                    }

                    else if (animalType == "Tomcat")
                    {
                        var tomcat = new Tomcat(animalName, animalAge);
                        Console.WriteLine(tomcat);
                    }
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }
            }
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();
            string        cmd     = Console.ReadLine();

            while (cmd != "Beast!")
            {
                string[] tokens = Console.ReadLine()
                                  .Split(' ', StringSplitOptions.RemoveEmptyEntries);

                string name   = tokens[0];
                int    age    = int.Parse(tokens[1]);
                string gender = tokens[2];


                if (string.IsNullOrEmpty(name) ||
                    int.Parse(tokens[1]) < 0 ||
                    string.IsNullOrEmpty(gender))

                {
                    Console.WriteLine("Invalid input!");
                }
                else
                {
                    if (cmd == "Dog")
                    {
                        Dog current = new Dog(name, age, gender);
                        Console.WriteLine(current);
                        Console.WriteLine(current.ProduceSound());
                    }
                    else if (cmd == "Cat")
                    {
                        Cat currentCat = new Cat(name, age, gender);
                        Console.WriteLine(currentCat);
                        Console.WriteLine(currentCat.ProduceSound());
                    }
                    else if (cmd == "Frog")
                    {
                        Frog currentFrog = new Frog(name, age, gender);
                        Console.WriteLine(currentFrog);
                        Console.WriteLine(currentFrog.ProduceSound());
                    }
                    else if (cmd == "Tomcat")
                    {
                        Tomcat currentTom = new Tomcat(name, age);
                        Console.WriteLine(currentTom);
                        Console.WriteLine(currentTom.ProduceSound());
                    }
                    else if (cmd == "Kitten")
                    {
                        Kitten currentKitty = new Kitten(name, age);
                        Console.WriteLine(currentKitty);
                        Console.WriteLine(currentKitty.ProduceSound());
                    }
                }
                cmd = Console.ReadLine();
            }
        }
Exemplo n.º 21
0
        public static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

            string animalType;

            while ((animalType = Console.ReadLine()) != "Beast!")
            {
                string[] line = Console.ReadLine().Split();

                try
                {
                    string name   = line[0];
                    int    age    = int.Parse(line[1]);
                    string gender = string.Empty;

                    switch (animalType)
                    {
                    case "Cat":
                        gender = line[2];
                        Cat cat = new Cat(name, age, gender);
                        animals.Add(cat);
                        break;

                    case "Dog":
                        gender = line[2];
                        Dog dog = new Dog(name, age, gender);
                        animals.Add(dog);
                        break;

                    case "Frog":
                        gender = line[2];
                        Frog frog = new Frog(name, age, gender);
                        animals.Add(frog);
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(name, age);
                        animals.Add(kitten);
                        break;

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(name, age);
                        animals.Add(tomcat);
                        break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            animals.ForEach(Console.WriteLine);
        }
Exemplo n.º 22
0
        public static void Main(string[] args)
        {
            while (true)
            {
                var line = System.Console.ReadLine();
                if (line == "Beast!")
                {
                    break;
                }
                var data   = System.Console.ReadLine().Split();
                var name   = data[0];
                var age    = int.Parse(data[1]);
                var gender = data[2];

                if (string.IsNullOrEmpty(name) || age < 0 || string.IsNullOrEmpty(gender))
                {
                    Console.WriteLine("Invalid input!");
                    continue;
                }

                if (line == "Cat")
                {
                    var cat = new Cat(name, age, gender);

                    Console.WriteLine(cat);
                    cat.ProduceSound();
                }
                else if (line == "Dog")
                {
                    var dog = new Dog(name, age, gender);

                    Console.WriteLine(dog);
                    dog.ProduceSound();
                }
                else if (line == "Frog")
                {
                    var frog = new Frog(name, age, gender);

                    Console.WriteLine(frog);
                    frog.ProduceSound();
                }
                else if (line == "Tomcat")
                {
                    var tomcat = new Tomcat(name, age);

                    Console.WriteLine(tomcat);
                    tomcat.ProduceSound();
                }
                else if (line == "Kitten")
                {
                    var kitten = new Kitten(name, age);

                    Console.WriteLine(kitten);
                    kitten.ProduceSound();
                }
            }
        }
Exemplo n.º 23
0
        public static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "Beast!")
            {
                string[] details = Console.ReadLine().Split();
                string   name    = details[0];
                int      age     = int.Parse(details[1]);
                string   gender  = details[2];

                try
                {
                    switch (input.Trim())
                    {
                    case "Dog":
                        Animal dog = new Dog(name, age, gender);
                        animals.Add(dog);
                        break;

                    case "Cat":
                        Animal cat = new Cat(name, age, gender);
                        animals.Add(cat);
                        break;

                    case "Frog":
                        Animal frog = new Frog(name, age, gender);
                        animals.Add(frog);
                        break;

                    case "Kittens":
                        Animal kitten = new Kitten(name, age);
                        animals.Add(kitten);
                        break;

                    case "Tomcat":
                        Animal tomcat = new Tomcat(name, age);
                        animals.Add(tomcat);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            foreach (var pet in animals)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(pet.GetType().Name);
                sb.AppendLine(pet.ToString());
                sb.AppendLine(pet.ProduceSound());
                Console.WriteLine(sb.ToString().TrimEnd());
            }
        }
Exemplo n.º 24
0
        static void Main()
        {
            // Cats
            var    cats = new List <Cat>();
            Kitten femaleCat;

            femaleCat = new Kitten("Loly", 3);
            cats.Add(femaleCat);

            femaleCat = new Kitten("Moly", 12);
            cats.Add(femaleCat);

            femaleCat = new Kitten("Doly", 2);
            cats.Add(femaleCat);

            var    maleCats = new List <TomCat>();
            TomCat maleCat;

            maleCat = new TomCat("Tom", 6);
            cats.Add(maleCat);

            maleCat = new TomCat("Maxuel", 10);
            cats.Add(maleCat);

            maleCat = new TomCat("Muri", 1);
            cats.Add(maleCat);

            // Dogs
            var dogs = new List <Dog>();
            Dog dog;

            dog = new Dog("Sharo", 8, "male");
            dogs.Add(dog);

            dog = new Dog("Pesho", 6, "male");
            dogs.Add(dog);

            dog = new Dog("Kaya", 3, "female");
            dogs.Add(dog);

            // Frogs
            var  frogs = new List <Frog>();
            Frog frog;

            frog = new Frog("Kvaki", 5, "male");
            frogs.Add(frog);

            frog = new Frog("Kvuki", 12, "male");
            frogs.Add(frog);

            frog = new Frog("Kveki", 2, "female");
            frogs.Add(frog);

            Console.WriteLine("Avarage cats age is {0}", cats.Average(c => c.Age));
            Console.WriteLine("Avarage dog age is {0}", dogs.Average(d => d.Age));
            Console.WriteLine("Avarage frog age is {0}", frogs.Average(f => f.Age));
        }
Exemplo n.º 25
0
        public static void Main()
        {
            var animalType = Console.ReadLine();

            while (animalType != "Beast!")
            {
                try
                {
                    var animalParams = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    var name         = animalParams[0];
                    var gender       = animalParams[2];

                    int age;

                    if (!int.TryParse(animalParams[1], out age))
                    {
                        throw new InvalidInputExeptions();
                    }

                    switch (animalType)
                    {
                    case "Cat":
                        var cat = new Cat(name, age, gender);
                        Console.WriteLine(cat);
                        break;

                    case "Kitten":
                        var kitten = new Kitten(name, age);
                        Console.WriteLine(kitten);
                        break;

                    case "Tomcat":
                        var tomcat = new Tomcat(name, age);
                        Console.WriteLine(tomcat);
                        break;

                    case "Frog":
                        var frog = new Frog(name, age, gender);
                        Console.WriteLine(frog);
                        break;

                    case "Dog":
                        var dog = new Dog(name, age, gender);
                        Console.WriteLine(dog);
                        break;

                    default: throw new InvalidInputExeptions();
                    }
                }
                catch (InvalidInputExeptions e)
                {
                    Console.WriteLine(e.Message);
                }

                animalType = Console.ReadLine();
            }
        }
Exemplo n.º 26
0
        public static void Main(string[] args)
        {
            while (true)
            {
                string animal = Console.ReadLine();
                {
                    if (animal == "Beast!")
                    {
                        break;
                    }
                }

                string[] animalInfo = Console.ReadLine().Split();

                string name   = animalInfo[0];
                int    age    = int.Parse(animalInfo[1]);
                string gender = animalInfo[2];

                if (string.IsNullOrEmpty(name) ||
                    age < 0 ||
                    (gender != "Male" && gender != "Female"))
                {
                    Console.WriteLine("Invalid input!");
                    continue;
                }

                switch (animal)
                {
                case "Dog":
                    Dog dog = new Dog(name, age, gender);
                    Console.WriteLine(dog);
                    break;

                case "Cat":
                    Cat cat = new Cat(name, age, gender);
                    Console.WriteLine(cat);
                    break;

                case "Frog":
                    Frog frog = new Frog(name, age, gender);
                    Console.WriteLine(frog);
                    break;

                case "Kitten":
                    Kitten kitten = new Kitten(name, age);
                    Console.WriteLine(kitten);
                    break;

                case "Tomcat":
                    Tomcat tomcat = new Tomcat(name, age);
                    Console.WriteLine(tomcat);
                    break;
                }

                animal = Console.ReadLine();
            }
        }
        static void Main(string[] args)
        {
            var    animals = new Queue <Animal>();
            string animalType;

            while ((animalType = Console.ReadLine()) != "Beast!")
            {
                var currentAnimalTokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                try
                {
                    switch (animalType.Trim())
                    {
                    case "Cat":
                        Animal cat = new Cat(currentAnimalTokens[0], int.Parse(currentAnimalTokens[1]), currentAnimalTokens[2]);
                        animals.Enqueue(cat);
                        break;

                    case "Dog":
                        Animal dog = new Dog(currentAnimalTokens[0], int.Parse(currentAnimalTokens[1]), currentAnimalTokens[2]);
                        animals.Enqueue(dog);
                        break;

                    case "Frog":
                        Animal frog = new Frog(currentAnimalTokens[0], int.Parse(currentAnimalTokens[1]), currentAnimalTokens[2]);
                        animals.Enqueue(frog);
                        break;

                    case "Kitten":
                        Animal kitten = new Kitten(currentAnimalTokens[0], int.Parse(currentAnimalTokens[1]));
                        animals.Enqueue(kitten);
                        break;

                    case "Tomcat":
                        Animal tomcat = new Tomcat(currentAnimalTokens[0], int.Parse(currentAnimalTokens[1]));
                        animals.Enqueue(tomcat);
                        break;

                    default:
                        Console.WriteLine("Invalid input!");
                        break;
                    }
                }
                catch (ArgumentException ArgEx)
                {
                    Console.WriteLine(ArgEx.Message);;
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.GetType().Name);
                Console.WriteLine($"{animal.Name} {animal.Age} {animal.Gender}");
                animal.ProduceSound();
            }
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            var    animals = new List <Animal>();
            Animal animal  = null;

            while (true)
            {
                var command = Console.ReadLine();
                if (command == "Beast!")
                {
                    break;
                }

                var animalArgs = Console.ReadLine().Split();

                var name   = animalArgs[0];
                var age    = int.Parse(animalArgs[1]);
                var gender = animalArgs[2];

                try
                {
                    if (command == "Dog")
                    {
                        animal = new Dog(name, age, gender);
                    }

                    else if (command == "Frog")
                    {
                        animal = new Frog(name, age, gender);
                    }
                    else if (command == "Cat")
                    {
                        animal = new Cat(name, age, gender);
                    }
                    else if (command == "Kitten")
                    {
                        animal = new Kitten(name, age);
                    }
                    else if (command == "Tomcat")
                    {
                        animal = new Tomcat(name, age);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }

                animals.Add(animal);
            }



            Console.WriteLine(string.Join(Environment.NewLine, animals));
        }
Exemplo n.º 29
0
        public static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();
            string        command;

            while ((command = Console.ReadLine()) != "Beast!")
            {
                string[] animalDetails = Console.ReadLine().Split(' ');
                string   name          = animalDetails[0];
                int      age           = int.Parse(animalDetails[1]);

                try
                {
                    switch (command)
                    {
                    case "Dog":
                        Dog dog = new Dog(name, age, animalDetails[2]);
                        animals.Add(dog);
                        break;

                    case "Cat":
                        Cat cat = new Cat(name, age, animalDetails[2]);
                        animals.Add(cat);
                        break;

                    case "Frog":
                        Frog frog = new Frog(name, age, animalDetails[2]);
                        animals.Add(frog);
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(name, age);
                        animals.Add(kitten);
                        break;

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(name, age);
                        animals.Add(tomcat);
                        break;

                    default:
                        throw new ArgumentException();
                    }
                }
                catch (ArgumentException)
                {
                    Console.WriteLine("Invalid input!");
                }
            }


            foreach (Animal item in animals)
            {
                Console.WriteLine(item);
            }
        }
Exemplo n.º 30
0
        public static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

            while (true)
            {
                string input = Console.ReadLine().ToLower();
                if (input.Equals("beast!"))
                {
                    break;
                }
                string[] tokens = Console.ReadLine().Split();
                var      animal = new Animal();
                string   name   = tokens[0];
                int      age    = int.Parse(tokens[1]);
                string   gender = tokens[2];
                try
                {
                    switch (input)
                    {
                    case "cat":
                        animal = new Cat(name, age, gender);
                        break;

                    case "dog":
                        animal = new Dog(name, age, gender);
                        break;

                    case "frog":
                        animal = new Frog(name, age, gender);
                        break;

                    case "tomcat":
                        animal = new Tomcat(name, age, gender);
                        break;

                    case "kittens":
                        animal = new Kitten(name, age, gender);
                        break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                    animals.Add(animal);
                }
                catch (Exception massage)
                {
                    Console.WriteLine(massage);;
                }
            }
            foreach (var currentAnimal in animals)
            {
                Console.WriteLine(currentAnimal);
                currentAnimal.ProduceSound();
            }
        }
        static void Main()
        {
            // Attention! - No animals were harmed during these tests

            Console.Title = "Animals";

            var dog = new Dog("Gosho", 3, Gender.Male);
            Console.WriteLine(dog);
            dog.FetchStick();
            Console.Write(Environment.NewLine);

            var frog = new Frog("Masha", 16, Gender.Female);
            Console.WriteLine(frog);
            frog.Transform();
            Console.Write(Environment.NewLine);

            var kitty = new Kitten("Maca", 0);
            Console.WriteLine(kitty);
            kitty.MeltYourHeart();
            Console.Write(Environment.NewLine);

            var tomcat = new Tomcat("Tom", 4);
            Console.WriteLine(tomcat);
            tomcat.Piss();
            Console.Write(Environment.NewLine);

            var animals = new Animal[]
            {
                new Dog("Freya", 1, Gender.Female),
                new Dog("Sharo", 4, Gender.Male),
                new Frog("Penka", 20, Gender.Female),
                new Frog("Fred", 32, Gender.Male),
                new Kitten("Merlin", 1),
                new Kitten("Shusia", 0),
                new Tomcat("Felix",6),
                new Tomcat("Silvester", 5),
            };

            var averageAge = from an in animals
                group an by new
                {
                    GroupName = an.GetType().Name
                }
                into gender select new
                {
                    gender.Key.GroupName,
                    AvarageAge = gender.Average(an => an.Age)
                };

            foreach (var animal in averageAge)
            {
                Console.WriteLine(String.Format("Group: {0}, AvarageAge: {1:0.00}.", animal.GroupName, animal.AvarageAge));
            }

            // And what does the Fox say? Oh, no foxes here...
        }
Exemplo n.º 32
0
        public static void Main(string[] args)
        {
            string input = string.Empty;

            while ((input = Console.ReadLine()) != "Beast!")
            {
                string[] tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

                string name   = tokens[0];
                int    age    = int.Parse(tokens[1]);
                string gender = tokens[2];
                try
                {
                    switch (input)
                    {
                    case "Dog":
                        Dog dog = new Dog(name, age, gender);
                        Console.WriteLine(dog);
                        dog.ProduceSound();
                        break;

                    case "Frog":
                        Frog frog = new Frog(name, age, gender);
                        Console.WriteLine(frog);
                        frog.ProduceSound();
                        break;

                    case "Cat":
                        Cat cat = new Cat(name, age, gender);
                        Console.WriteLine(cat);
                        cat.ProduceSound();
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(name, age);
                        Console.WriteLine(kitten);
                        kitten.ProduceSound();
                        break;

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(name, age);
                        Console.WriteLine(tomcat);
                        tomcat.ProduceSound();
                        break;

                    default:
                        throw new Exception("Invalid input!");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Exemplo n.º 33
0
        public void Run()
        {
            while (true)
            {
                try
                {
                    string typeAnimal = Console.ReadLine();
                    if (typeAnimal == "Beast!")
                    {
                        break;
                    }

                    if (typeAnimal.ToLower() == "cat")
                    {
                        string[] input = Console.ReadLine().Split();

                        Cat cat = new Cat(input[0], int.Parse(input[1]), input[2]);

                        Console.WriteLine(cat);
                    }
                    else if (typeAnimal.ToLower() == "dog")
                    {
                        string[] input = Console.ReadLine().Split();

                        Dog dog = new Dog(input[0], int.Parse(input[1]), input[2]);
                        Console.WriteLine(dog);
                    }
                    else if (typeAnimal.ToLower() == "frog")
                    {
                        string[] input = Console.ReadLine().Split();

                        Frog frog = new Frog(input[0], int.Parse(input[1]), input[2]);
                        Console.WriteLine(frog);
                    }
                    else if (typeAnimal.ToLower() == "kitten")
                    {
                        string[] input = Console.ReadLine().Split();

                        Kitten kitten = new Kitten(input[0], int.Parse(input[1]));
                        Console.WriteLine(kitten);
                    }
                    else if (typeAnimal.ToLower() == "tomcat")
                    {
                        string[] input = Console.ReadLine().Split();

                        Tomcat tomcat = new Tomcat(input[0], int.Parse(input[1]));
                        Console.WriteLine(tomcat);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 34
0
        public static void Main(string[] args)
        {
            string animalType = Console.ReadLine();

            while (animalType != "Beast!")
            {
                string[] animalLine = Console.ReadLine().Split(" ");
                try
                {
                    string name   = animalLine[0];
                    int    age    = int.Parse(animalLine[1]);
                    string gender = string.Empty;

                    switch (animalType)
                    {
                    case "Cat":
                        gender = animalLine[2];
                        var cat = new Cat(name, age, gender);
                        Console.WriteLine(cat);
                        break;

                    case "Dog":
                        gender = animalLine[2];
                        var dog = new Dog(name, age, gender);
                        Console.WriteLine(dog);
                        break;

                    case "Frog":
                        gender = animalLine[2];
                        var frog = new Frog(name, age, gender);
                        Console.WriteLine(frog);
                        break;

                    case "Kitten":
                        var kitten = new Kitten(name, age);
                        Console.WriteLine(kitten);
                        break;

                    case "Tomcat":
                        var tomcat = new Tomcat(name, age);
                        Console.WriteLine(tomcat);
                        break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animalType = Console.ReadLine();
            }
        }
Exemplo n.º 35
0
        public static void Main()
        {
            List <Animal> animals = new List <Animal>();

            while (true)
            {
                string firstLine = Console.ReadLine();

                if (firstLine == "Beast!")
                {
                    Print(animals);
                    break;
                }

                string[] secondLineTokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

                try
                {
                    switch (firstLine)
                    {
                    case "Dog":
                        var dog = new Dog(secondLineTokens[0], int.Parse(secondLineTokens[1]), secondLineTokens[2]);
                        animals.Add(dog);
                        break;

                    case "Frog":
                        var frog = new Frog(secondLineTokens[0], int.Parse(secondLineTokens[1]), secondLineTokens[2]);
                        animals.Add(frog);
                        break;

                    case "Cat":
                        var cat = new Cat(secondLineTokens[0], int.Parse(secondLineTokens[1]), secondLineTokens[2]);
                        animals.Add(cat);
                        break;

                    case "Kitten":
                        var kitten = new Kitten(secondLineTokens[0], int.Parse(secondLineTokens[1]));
                        animals.Add(kitten);
                        break;

                    case "Tomcat":
                        var tomcat = new Tomcat(secondLineTokens[0], int.Parse(secondLineTokens[1]));
                        animals.Add(tomcat);
                        break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 36
0
        public static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "Beast!")
                {
                    break;
                }


                string[] tokens = Console.ReadLine().Split();

                string name   = tokens[0];
                int    age    = int.Parse(tokens[1]);
                string gender = tokens[2];

                if (age < 0)
                {
                    Console.WriteLine("Invalid input!");
                    continue;
                }

                if (input == "Frog")
                {
                    Frog frog = new Frog(name, age, gender);
                    Console.WriteLine(frog);
                    frog.ProduceSound();
                }
                else if (input == "Dog")
                {
                    Dog dog = new Dog(name, age, gender);
                    Console.WriteLine(dog);
                    dog.ProduceSound();
                }
                else if (input == "Cat")
                {
                    Cat cat = new Cat(name, age, gender);
                    Console.WriteLine(cat);
                    cat.ProduceSound();
                }
                else if (input == "Tomcat")
                {
                    Tomcat tomcat = new Tomcat(name, age);
                    Console.WriteLine(tomcat);
                    tomcat.ProduceSound();
                }
                else if (input == "Kitten")
                {
                    Kitten kitten = new Kitten(name, age);
                    Console.WriteLine(kitten);
                    kitten.ProduceSound();
                }
            }
        }
        public static void Main(string[] args)
        {
            string command = Console.ReadLine();

            while (command != "Beast!")
            {
                string[] tokens = Console.ReadLine().Split();

                if (tokens.Length == 3 &&
                    char.IsLetter(tokens[0][0]) &&
                    int.TryParse(tokens[1], out int x) &&
                    x >= 0 &&
                    (tokens[2].ToLower() == "male" || tokens[2] == "female"))
                {
                    string typeOfAnimal = command;

                    string name = tokens[0];
                    int    age  = int.Parse(tokens[1]);
                    string sex  = tokens[2];

                    if (typeOfAnimal == "Cat")
                    {
                        Cat cat = new Cat(name, age, sex);
                        Console.WriteLine(cat.ToString());
                    }
                    else if (typeOfAnimal == "Dog")
                    {
                        Dog dog = new Dog(name, age, sex);
                        Console.WriteLine(dog.ToString());
                    }
                    else if (typeOfAnimal == "Frog")
                    {
                        Frog frog = new Frog(name, age, sex);
                        Console.WriteLine(frog.ToString());
                    }
                    else if (typeOfAnimal == "Kitten")
                    {
                        Kitten kitten = new Kitten(name, age);
                        Console.WriteLine(kitten.ToString());
                    }
                    else if (typeOfAnimal == "Tomcat")
                    {
                        Tomcat tomcat = new Tomcat(name, age);
                        Console.WriteLine(tomcat.ToString());
                    }
                }
                else
                {
                    Console.WriteLine("Invalid input!");
                }

                command = Console.ReadLine();
            }
        }
Exemplo n.º 38
0
        public static void Main(string[] args)
        {
            string animalType = System.Console.ReadLine();

            while (animalType != "Beast!")
            {
                string[] nameAgeGender = System.Console.ReadLine()
                                         .Split();
                string name = nameAgeGender[0];

                int age = int.Parse(nameAgeGender[1]);

                string gender = nameAgeGender[2];

                if ((name == String.Empty) || (age <= 0) ||
                    (gender != "Male" && gender != "Female"))
                {
                    Console.WriteLine("Invalid input!");
                }

                Animal animal;

                switch (animalType)
                {
                case "Dog":
                    animal = new Dog(name, age, gender);
                    break;

                case "Cat":
                    animal = new Cat(name, age, gender);
                    break;

                case "Frog":
                    animal = new Frog(name, age, gender);
                    break;

                case "Kitten":
                    animal = new Kitten(name, age);
                    break;

                default: animal = new Tomcat(name, age);
                    break;
                }

                if (gender != String.Empty && age > 0 && gender != String.Empty)
                {
                    Console.WriteLine(animalType);
                    Console.WriteLine($"{animal.Name} {animal.Age} {animal.Gender}");
                    Console.WriteLine(animal.ProduceSound());
                }

                animalType = Console.ReadLine();
            }
        }
Exemplo n.º 39
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

            string input = Console.ReadLine();

            while (input != "Beast!")
            {
                try
                {
                    string[] info = Console.ReadLine()
                                    .Split(' ', StringSplitOptions.RemoveEmptyEntries);

                    switch (input)
                    {
                    case "Cat":
                        Cat cat = new Cat(info[0], int.Parse(info[1]), info[2]);
                        animals.Add(cat);
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(info[0], int.Parse(info[1]));
                        animals.Add(kitten);
                        break;

                    case "Tomcat":
                        Tomcat tomCat = new Tomcat(info[0], int.Parse(info[1]));
                        animals.Add(tomCat);
                        break;

                    case "Dog":
                        Dog dog = new Dog(info[0], int.Parse(info[1]), info[2]);
                        animals.Add(dog);
                        break;

                    case "Frog":
                        Frog frog = new Frog(info[0], int.Parse(info[1]), info[2]);
                        animals.Add(frog);
                        break;
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 40
0
        static void Main()
        {
            Dog dog = new Dog("Sharo", 5, Gender.Male);
            Console.WriteLine(dog);

            Console.WriteLine();

            Frog frog = new Frog("Kermit", 33, Gender.Male);
            Console.WriteLine(frog);

            Console.WriteLine();

            Kitten kitty = new Kitten("Kitty", 1);
            Console.WriteLine(kitty);

            Console.WriteLine();

            Tomcat tomcat = new Tomcat("Tom", 12);
            Console.WriteLine(tomcat);

            Console.WriteLine();


            List<Animal> animals = new List<Animal>()
            {
                new Dog("Rex",3, Gender.Male),
                new Frog("Kekerica", 1, Gender.Female),
                new Kitten("Pisi", 1),
                new Tomcat("Tom",2),
                new Dog("Erik", 4, Gender.Male),
                new Frog("Penka", 1, Gender.Female),
                new Kitten("Jasmin", 2),
                new Tomcat("Kolio",6),
                new Dog("Bender",2, Gender.Male),
                new Frog("Ginka", 6, Gender.Female),
                new Kitten("Tedy", 1),
                new Tomcat("Muncho",4),
            };

            var avgGradeForCurrentAnimal = animals
                .GroupBy(x => x.GetType().Name)
                .Select(a => new
                {
                    Name = a.Key,
                    AvgAge = a.Average(g => g.Age)
                });

            foreach (var currAnimal in avgGradeForCurrentAnimal)
            {
                Console.WriteLine(currAnimal);
            }
        }
Exemplo n.º 41
0
        static void Main(string[] args)
        {
            Dog pinchi = new Dog("Pinchi", 2, "male", "bauuuuuuuu");
            Dog suzi = new Dog("Pinchi", 4, "male", "bauuuuuuuu");
            Dog djeimi = new Dog("Pinchi", 4, "male", "bauuuuuuuu");

            Kitten mimi = new Kitten("kitten", 5, "female", "miiiauuu");
            Kitten kuki = new Kitten("kitten", 5, "female", "miiiauuu");

            Tomcat tom = new Tomcat("Top4o", 15, "male", "myuuuu");

            Frog crazy = new Frog("Crazy Frog", 10, "male", "Kvaaa");
            Console.WriteLine(Frog.AverageFrog().Count());
        }
Exemplo n.º 42
0
        static void Main(string[] args)
        {
            var frog1 = new Frog(25, "jaba1", true);
            var frog2 = new Frog(20, "jaba2", false);
            var frog3 = new Frog(25, "jaba3", true);
            var frog4 = new Frog(20, "jaba4", false);
            var allFrogs=new Frog[]{frog1,frog2,frog3,frog4};

            var dog1 = new Dog(30, "kuche1", true);
            var dog2 = new Dog(30, "kuche2", true);
            var dog3 = new Dog(30, "kuche3", true);
            var allDogs=new Dog[]{dog1,dog2,dog3};

            var randomCat1 = new Cat(5, "random kotka1", false);
            var randomCat2 = new Cat(13, "random kotka2", false);
            var randomCat3 = new Cat(5, "random kotka3",true);
            var allCats=new Cat[]{randomCat1,randomCat2,randomCat3};

            var femaleCat1 = new Kitten(5, "jenska kotka1");
            var femaleCat2 = new Kitten(43, "jenska kotka2");
            var femaleCat3 = new Kitten(56, "jenska kotka3");
            var allFemaleCats=new Kitten[]{femaleCat1,femaleCat2,femaleCat3};

            var maleCat1 = new TomCat(5, "mujka kotka1");
            var maleCat2 = new TomCat(6, "mujka kotka2");
            var maleCat3 = new TomCat(200, "mujka kotka3");
            var allMaleCats=new TomCat[]{maleCat1,maleCat2,maleCat3};

            var frogs = allFrogs.Average(x => x.Age);
            Console.WriteLine("The avergae age of frogs is: {0}",frogs);

            var dogs = allDogs.Average(x => x.Age);
            Console.WriteLine("The avergae age of dogs is: {0}", dogs);

            var cats = allCats.Average(x => x.Age);
            Console.WriteLine("The avergae age of  random cats is: {0}", cats);

            var femaleCats = allFemaleCats.Average(x => x.Age);
            Console.WriteLine("The avergae age of female cats(Kittens) is: {0}", femaleCats);

            var maleCats = allMaleCats.Average(x => x.Age);
            Console.WriteLine("The avergae age of male cats(Tomcats) is: {0}", maleCats);
            Console.WriteLine(randomCat1.MakeSound());
        }
Exemplo n.º 43
0
        static void Main()
        {
            Cat someCat = new Cat("Kotka", 10);
            Cat someCat1 = new Cat("Kotka1", 5);

            Tomcat tom = new Tomcat("Tom", 4, Gender.Male);
            Tomcat tom1 = new Tomcat("Tom1", 3, Gender.Male);

            Kitten maca = new Kitten("Maca",2,Gender.Female);
            Kitten maca1 = new Kitten("Maca1", 6, Gender.Female);

            Dog sharo = new Dog("Sharo", 3);
            Dog sharo1 = new Dog("Sharo1", 1);

            Frog frogy = new Frog("Frogy", 8);
            Frog frogy1 = new Frog("Frogy1", 2);

            Console.WriteLine(someCat);
            Console.WriteLine(tom);
            Console.WriteLine( maca);
            Console.WriteLine(sharo);
            Console.WriteLine(frogy);

            IList<Animal> allAnimal = new List<Animal>();
            allAnimal.Add(someCat);
            allAnimal.Add(someCat1);
            allAnimal.Add(tom);
            allAnimal.Add(tom1);
            allAnimal.Add(maca);
            allAnimal.Add(maca1);
            allAnimal.Add(sharo);
            allAnimal.Add(sharo1);
            allAnimal.Add(frogy);
            allAnimal.Add(frogy1);

            foreach (var kind in allAnimal.GroupBy(x => x.GetType().Name))
            {
                double averageAge = kind.Select(x => x.Age).Average();
                Console.WriteLine("Animal : {0}, AverageAge: {1}", kind.Key, averageAge);
            }
        }
Exemplo n.º 44
0
        static void Main()
        {
            Random rand = new Random();
            Dog[] dogs = new Dog[5];
            Frog[] frogs = new Frog[5];
            Cat[] cats = new Cat[5];
            Kitten[] kittens = new Kitten[5];
            Tomcat[] tomcats = new Tomcat[5];
            for (int i = 0; i < 5; i++)
            {
                int age=rand.Next(0,30);
                Dog dog = new Dog(age, Convert.ToString((char)(age + 65)), "male");
                dogs[i] = dog;

                age = rand.Next(0, 30);
                Frog frog = new Frog(age, Convert.ToString((char)(age + 65)), "male");
                frogs[i] = frog;

                age = rand.Next(0, 30);
                Kitten kiten = new Kitten(age, Convert.ToString((char)(age + 65)), "male");
                kittens[i] = kiten;

                age = rand.Next(0, 30);
                Cat cat = new Cat(age, Convert.ToString((char)(age + 65)), "male");
                cats[i] = cat;

                age = rand.Next(0, 30);
                Tomcat tomcat = new Tomcat(age, Convert.ToString((char)(age + 65)), "male");
                tomcats[i] = tomcat;
            }
            Print(dogs);
            Print(cats);
            Print(kittens);
            Print(frogs);
            Print(tomcats);
            Console.WriteLine("The average age of the dogs is {0}", AverageAge(dogs));
            Console.WriteLine("The average age of the cats is {0}", AverageAge(cats));
            Console.WriteLine("The average age of the kittens is {0}", AverageAge(kittens));
            Console.WriteLine("The average age of the frogs is {0}", AverageAge(frogs));
            Console.WriteLine("The average age of the tomcats is {0}", AverageAge(tomcats));
        }
Exemplo n.º 45
0
        static void Main(string[] args)
        {
            Animal[] animals = new Animal[5];
            animals[0]=new Cat("Mac",10,Gender.Male);
            animals[1]=new Kitten("Max",2);
            animals[2]=new Kitten("Missi",1);
            animals[3]=new Frog("Kermit",3,Gender.Male);
            animals[4]=new Frog("Tom",5,Gender.Male);
            animals.ToList();

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
                animal.ProduceSoun();
            }

             animals.GroupBy(t=>t.GetType().Name)
                .Select(group=>new {AnimalName=group.Key,AvarageAge=group.Average(a=>a.Age)})
                .ToList()
                .ForEach(group=>Console.WriteLine("{0}{1}",group.AnimalName,group.AvarageAge));
        }
Exemplo n.º 46
0
        static void Main()
        {
            Tomcat tom = new Tomcat("Tom", 12);
            Console.WriteLine(tom);
            Kitten kitty = new Kitten("Kitty", 3);
            Console.WriteLine(kitty);
            Console.WriteLine();

            List<ISound> listAnimals = new List<ISound>();
            listAnimals.Add(new Cat("Pepi", 3, "female"));
            listAnimals.Add(new Frog("Kurmit", 10, "male"));
            listAnimals.Add(new Dog("Sharo", 5, "male"));
            listAnimals.Add(new Cat("Jorko", 6, "male"));
            listAnimals.Add(new Dog("Balkan", 10, "male"));
            listAnimals.Add(kitty);
            listAnimals.Add(tom);
            foreach (var animal in listAnimals)
            {
                Console.WriteLine(animal + " " + animal.MakeSound());
            }

            Console.WriteLine();

            Animal[] animals = new Animal[]
            {
                new Cat("Pepi", 3, "female"),
                new Frog("Kurmit", 10, "male"),
                new Dog("Sharo", 5, "male"),
                new Cat("Jorko", 6, "male"),
                new Cat("Tom",12,"male")
            };

               Console.WriteLine(Animal.GetAvaregeAge(animals));

               var ages =
               (from animal in animals
                where animal.GetType() == typeof(Cat)
                select animal.age).Average();
               Console.WriteLine(ages);
        }
Exemplo n.º 47
0
        static void Main()
        {
            Dog[] dogsArray = {
                                 new Dog ("Sharo", 3, "male"),
                                 new Dog ("Reks", 2, "male"),
                                 new Dog ("Diva", 1, "female"),
                                 new Dog ("Atila", 3, "male"),
                                 new Dog ("Ronia", 2, "female")
                             };

            Cat[] catsArray = {
                                 new Cat ("Linda", 5, "female"),
                                 new Cat ("Reksy", 2, "male"),
                                 new Cat ("Lula", 1, "female"),
                                 new Cat ("Scruffy", 7, "male"),
                                 new Cat ("Lucky", 1, "female")
                             };

            Frog[] frogsArray = {
                                 new Frog ("Tuti", 1, "female"),
                                 new Frog ("Muti", 0, "male"),
                                 new Frog ("Kuku", 1, "female"),
                                 new Frog ("Lulu", 0, "male"),
                                 new Frog ("Mumu", 0, "female")
                             };

            Kitten Kitty = new Kitten("Kitty", 2);

            //Test what animals say
            dogsArray[3].ProduceSound();
            catsArray[4].ProduceSound();
            frogsArray[0].ProduceSound();
            Kitty.ProduceSound();
            Console.WriteLine();

            //Print the avg age of each group of animals on the console
            Console.WriteLine("The average age of the dogs is: {0:F1} year/s/", Animal.CalculateAvgAge(dogsArray));
            Console.WriteLine("The average age of the cats is: {0:F1} year/s/", Animal.CalculateAvgAge(catsArray));
            Console.WriteLine("The average age of the frogs is: {0:F1} year/s/", Animal.CalculateAvgAge(frogsArray));
        }
Exemplo n.º 48
0
        private static void Main()
        {
            Dog barry = new Dog("Barry", 13, Gender.Male);
            Dog jessica = new Dog("Jessica", 6, Gender.Female);
            Dog milo = new Dog("Milo", 17, Gender.Male);

            Kitten dona = new Kitten("Dona", 6);
            Kitten sweety = new Kitten("Sweety", 0);
            Kitten sisi = new Kitten("Sisi", 4);

            Tomcat zorro = new Tomcat("Zorro", 7);
            Tomcat lucky = new Tomcat("Lucky", 7);
            Tomcat tom = new Tomcat("Tom", 7);

            Frog randy = new Frog("Randy", 3, Gender.Male);
            Frog bob = new Frog("Bob", 6, Gender.Male);
            Frog sw = new Frog("Sw", 2, Gender.Male);

            IList<Animal> allAnimal = new List<Animal>();
            allAnimal.Add(barry);
            allAnimal.Add(jessica);
            allAnimal.Add(milo);
            allAnimal.Add(dona);
            allAnimal.Add(sweety);
            allAnimal.Add(sisi);
            allAnimal.Add(zorro);
            allAnimal.Add(lucky);
            allAnimal.Add(tom);
            allAnimal.Add(randy);
            allAnimal.Add(bob);
            allAnimal.Add(sw);

            foreach (var kind in allAnimal.GroupBy(x => x.GetType().Name))
            {
                double averageAge = kind.Select(x => x.Age).Average();
                Console.WriteLine("Animal : {0}, average age are: {1:F2}", kind.Key, averageAge);
            }
        }
Exemplo n.º 49
0
        public static void Main()
        {
            Animal jaba = new Frog("baba jaba", 1, Genders.Female);
            Animal kekerica = new Frog("kekerica", 3, Genders.Female);

            Animal sharo = new Dog("sharo", 3, Genders.Male);
            Animal sara = new Dog("sara", 2, Genders.Female);
            Animal oldy = new Dog("oldy", 12, Genders.Male);

            Animal puhi = new Kitten("puhi", 2);
            Animal tommy = new Tomcat("tommy", 4);
            Animal mouseKiller = new Cat("mousy", 5, Genders.Male);

            List<Animal> animals = new List<Animal>()
            {
                jaba,
                kekerica,
                sharo,
                sara,
                puhi,
                tommy,
                mouseKiller,
                oldy
            };
            var groupedAnimals = from animal in animals
                                 group animal by (animal is Cat) ? typeof(Cat) : animal.GetType() into g
                                 select new { GroupName = g.Key, AverageAge = g.ToList().Average(an => an.Age) };

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

            puhi.ProduceSound();
            oldy.ProduceSound();
            jaba.ProduceSound();
        }
Exemplo n.º 50
0
        static void Main()
        {
            Kitten kitty = new Kitten("Pufi", 1); 
            Tomcat tomas = new Tomcat("Marko", 2);
            Dog sharo = new Dog("Kir4o", 3, SexEnum.male); 
            Frog squeek = new Frog("Kimi", 1, SexEnum.female); 
            kitty.MakeSomeNoise(); 
            tomas.MakeSomeNoise(); 
            sharo.MakeSomeNoise(); 
            squeek.MakeSomeNoise();
            
            Console.WriteLine(tomas.Gender); 
            Console.WriteLine(kitty.Gender); 

            Animal[] animals = 
            { 
                new Kitten("Koti", 2), 
                new Tomcat("Rocky", 4), 
                new Dog("Alex", 5, SexEnum.female), 
                new Frog("Siti", 2, SexEnum.female), 
                new Kitten("Kara", 6), 
                new Tomcat("Suzana", 2), 
                new Dog("Porsche", 7, SexEnum.female),
                new Frog("Kara", 10, SexEnum.female),
                new Kitten("Tonchi", 8), 
                new Tomcat("Jony", 8), 
                new Dog("Elma", 9, SexEnum.female), 
                new Frog("Liki", 5, SexEnum.female), 
            };

            var ordered = animals.GroupBy(x => x.GetType()); 
            Console.WriteLine(); 
            foreach (var animal in ordered) 
            { 
                Console.WriteLine("Average age of {0} is {1:F2}.", animal.Key.Name, animal.Average(x => x.Age));
            }
        }
Exemplo n.º 51
0
        static void Main(string[] args)
        {
            // Constructors test

            Kitten kity = new Kitten(10);

            Console.WriteLine("Kity's sex is : " + kity.Sex);

            Tomcat tommy = new Tomcat(10);

            Console.WriteLine("Tommy's sex is : " + tommy.Sex);

            Dog rex = new Dog(10,Sex.Male);

            Console.WriteLine("Rex's sex is : " + rex.Sex);
            Console.WriteLine("And Rex is {0} years old", rex.Age);

            Frog gogo = new Frog(100, Sex.Male);
            Console.WriteLine("Gogo the frog is {0} years old: ", gogo.Age);

            // Sounds test
            Console.WriteLine("__________________");
            Console.WriteLine("Frogs sound: ");
            gogo.ProduceSound();
            Console.WriteLine("__________________");
            Console.WriteLine("Tomcats sound: ");
            tommy.ProduceSound();
            Console.WriteLine("__________________");
            Console.WriteLine("Kittens sound: ");
            kity.ProduceSound();
            Console.WriteLine("__________________");
            Console.WriteLine("Dogs sound: ");
            rex.ProduceSound();

            Console.WriteLine();

            Dog[] dogs = new Dog[4]
            {
              new Dog(10,Sex.Male),
              new Dog(12,Sex.Male),
              new Dog(14,Sex.Male),
              new Dog(8,Sex.Male),
            };

            Frog[] frogs = new Frog[4]
            {
                new Frog(4,Sex.Male),
                new Frog(5,Sex.Male),
                new Frog(3,Sex.Male),
                new Frog(10,Sex.Male)

            };

            Kitten[] kities = new Kitten[4]
            {
                new Kitten(10),
                new Kitten(11),
                new Kitten(15),
                new Kitten(18)
            };

            Tomcat[] tomcats = new Tomcat[4]
            {
                new Tomcat(12),
                new Tomcat(15),
                new Tomcat(13),
                new Tomcat(40),
            };

            // Avarage age
            Console.WriteLine(" The avarage age of Tomcat is " + AvarageAge(tomcats));
            Console.WriteLine(" The avarage age of Kitten is " + AvarageAge(kities));
            Console.WriteLine(" The avarage age of Dogs is " + AvarageAge(dogs));
            Console.WriteLine(" The avarage age of Frogs is " + AvarageAge(frogs));

            Console.WriteLine();
        }
Exemplo n.º 52
0
        static void Main(string[] args)
        {
            Dog dog = new Dog("Pesho", 3, Gender.Male);
            Console.WriteLine(dog);
            dog.FetchStick();

            Console.WriteLine();

            Frog frog = new Frog("Peter", 33, Gender.Male);
            Console.WriteLine(frog);
            frog.Jump();

            Console.WriteLine();

            Kitten kitty = new Kitten("Ioio", 1);
            Console.WriteLine(kitty);
            kitty.Cry();

            Console.WriteLine();

            Tomcat tomcat = new Tomcat("Gogo", 12);
            Console.WriteLine(tomcat);
            tomcat.Piss();

            Console.WriteLine();

            // create an array of Animals
            Animal[] animals = new Animal[]
            {
                new Dog("Ares",3, Gender.Male),
                new Frog("Mitko", 1, Gender.Female),
                new Kitten("Mac", 1),
                new Tomcat("Cotka",2),
                new Dog("Saires", 4, Gender.Male),
                new Frog("Stilian", 1, Gender.Female),
                new Kitten("Ioio", 2),
                new Tomcat("Antony",6),
                new Dog("Roy",2, Gender.Male),
                new Frog("Angelina", 6, Gender.Female),
                new Kitten("Alex", 1),
                new Tomcat("Mecjo",4),
            };

            // calculate the aveage age of each animal and print them 
            var averageAge =
                from an in animals
                group an by new { GroupName = an.GetType().Name } into gr
                select new
                {
                    GroupName = gr.Key.GroupName,
                    AvarageAge = gr.Average(an => an.Age)
                };

            foreach (var animal in averageAge)
            {
                Console.WriteLine(String.Format("Group: {0}, AvarageAge: {1:0.00}.", animal.GroupName, animal.AvarageAge));
            }
        }
Exemplo n.º 53
0
        static void Main(string[] args)
        {
            try
            {
                Frog goshko = new Frog("Goshko", 10, "male");
                Frog peshko = new Frog("Peshko", 3, "male");
                Frog mariika = new Frog("Mariika", 7, "female");

                Dog ivancho = new Dog("Ivancho", 11, "male");
                Dog sashko = new Dog("Sashko", 1, "male");
                Dog magdalena = new Dog("Magdalena", 2, "female");

                Kitten tania = new Kitten("Tania", 3);
                Kitten penka = new Kitten("Penka", 4);
                Kitten goshka = new Kitten("Goshka", 10);

                Tomcat kristian = new Tomcat("Kristian", 1);
                Tomcat pesho = new Tomcat("Pesho", 10);
                Tomcat stanislav = new Tomcat("Stanislav", 5);

                IList<Animal> animals = new List<Animal>
                {
                    goshko, peshko, mariika, ivancho, sashko, magdalena,
                    tania, penka, goshka, kristian, pesho, stanislav
                };

                goshko.ProduceSound();
                sashko.ProduceSound();
                tania.ProduceSound();
                kristian.ProduceSound();

                double catsAverageAge = animals
                    .Where(animal => animal is Cat)
                    .Average(cat => cat.Age);

                double dogsAverageAge = animals
                    .Where(animal => animal is Dog)
                    .Average(dog => dog.Age);

                double frogsAverageAge = animals
                    .Where(animal => animal is Frog)
                    .Average(frog => frog.Age);

                Console.WriteLine("Frogs average age is: {0:F2}", frogsAverageAge);
                Console.WriteLine("Dogs average age is: {0:F2}", dogsAverageAge);
                Console.WriteLine("Cats average age is: {0:F2}", catsAverageAge);

            }
            catch (ArgumentOutOfRangeException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (ArgumentNullException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }
        }