Inheritance: Animals.Mammal, ILandAnimal
示例#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());
        }
示例#2
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));
        }
示例#3
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);
            
        }
示例#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);
            }
        }
示例#5
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);
            }
        }
示例#6
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);
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            Dog Sharo = new Dog(10, "Sharo", Sex.Male, "bao lau");
            Console.WriteLine(Sharo);
            Animal[] Animals = new Animal[] {

            new Tomcat(15, "Маци", "miau"),
            new Tomcat(11, "Котан", "miau miau"),
            new Tomcat(1, "Джери", "bau miau"),

            };

            Cat[] cats = new Cat[]
            {
            new PussyCat(1, "Мац", "bau miau"),
            new Tomcat(2, "Тим", "bau miau"),

            };

            Console.WriteLine("# Animals");
            foreach (Animal animal in Animals)
                Console.WriteLine(animal);

            Console.WriteLine("# Average");
            Console.WriteLine(Animals.Average(animal => animal.age));
            Console.WriteLine(cats.Average(cat => cat.age));
        }
示例#8
0
        static void Main(string[] args)
        {
            //var animal = new Animal();
            var dog = new Dog();
            var cat = new Cat();
            var snake = new Snake();

               // animal.Name = "Pesho";

            //Console.WriteLine(animal);
            //Console.WriteLine(animal.Greet());
            //Console.WriteLine(dog.Greet());
            //Console.WriteLine(cat.Greet());
            //Console.WriteLine(snake.Greet());

            var animals = new List<Animal>();
               // animals.Add(animal);
            animals.Add(dog);
            animals.Add(cat);
            animals.Add(snake);
            animals.Add(new Dog());
            animals.Add(new Dog());
            animals.Add(new Dog());

            var collectionOfDogs = animals.OfType<Dog>().Cast<Dog>();

            foreach (var anima in animals)
            {

                Console.WriteLine(anima);
            }
        }
        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));
            }
        }
        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...
        }
示例#11
0
        static void Main(string[] args)
        {
            var dog = new Dog();
            var responses = dog.Bark(0);

            foreach (var response in responses)
            {
                Console.WriteLine(response);
            }
        }
示例#12
0
 public static void Main(string[] args)
 {
     Animal cat1 = new Cat("Tom", 2, "male");
     Animal dog1 = new Dog("Tom", 5, "male");
     Animal cat2 = new Cat("Thomas", 18, "male");
     Animal[] animals =
     {
         cat1, dog1, cat2
     };
     var avg = animals.Average(x => x.Age);
     Console.WriteLine(avg);
 }
示例#13
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);
            }
        }
示例#14
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());
        }
 static void Main(string[] args)
 {
     Pigeon pigeon = new Pigeon();
     Dog dog1 = new Dog();
     Cat cat1 = new Cat();
     Dog dog2 = new Dog();
     Chameleon cham = new Chameleon();
     Marlin marl = new Marlin();
     List<Animals> animals = new List<Animals>();
     animals.Add((Animals)pigeon); animals.Add((Animals)dog1); animals.Add((Animals)dog2); animals.Add((Animals)cat1);animals.Add((Animals)cham);
     animals.Add((Animals)marl);
     foreach(Animals animal in animals)
     {
         animal.Eat();
         animal.Greet();
     }
 }
示例#16
0
        static void Main(string[] args)
        {
            Animal pesho = new Dog("Pesho", 19, "male");
            Cat tom = new Tomcat("Tommy", 12);
            Dog koche = new Dog("Koche", 10, "male");

            List<Animal> animals = new List<Animal>();

            animals.Add(pesho);
            animals.Add(tom);
            animals.Add(koche);

            animals.OrderBy(x=>x.Name).ToList().ForEach(Console.WriteLine);

            koche.ProduceSound();
            (pesho as Dog).ProduceSound();
            tom.ProduceSound();
        }
示例#17
0
        // Create arrays of different kinds of animals and calculate the average age of each kind of animal using a static method (you may use LINQ).
        private static void Main()
        {
            IEnumerable<Animal> dogs = new Dog[]
            {
                new Dog("Rex", true, 3),
                new Dog("Lassy", false, 4),
            };

            IEnumerable<Frog> frogs = new List<Frog>()
            {
                new Frog("Twig", true, 2),
                new Frog("Greenie", false, 8),
            };

            IEnumerable<Animal> tomcats = new List<Tomcat>()
            {
                new Tomcat("Tommy", 5)
            };

            IEnumerable<Animal> kittens = new List<Kitten>()
            {
                new Kitten("Kitty", 4)
            };

            IEnumerable<Animal> animals = new List<Animal>().Concat(dogs).Concat(frogs).Concat(tomcats).Concat(kittens);

            Console.WriteLine("ALL ANIMALS");
            Console.WriteLine("============");
            Console.WriteLine(string.Join(Environment.NewLine, animals));

            var grouped = animals.GroupBy(a => a.GetType());
            Console.WriteLine("\nAverage age of each kind:");
            foreach (var kind in grouped)
            {
                Console.WriteLine("{0,-7} - {1:F1}", kind.Key.Name + 's', kind.Average(x => x.Age));
            }

            Console.WriteLine("\nLet's make some noise...");
            foreach (var animal in animals)
            {
                Console.Write("{0} says: ", animal.Name);
                animal.MakeSound();
            }
        }
示例#18
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());
        }
        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);
            }
        }
示例#20
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));
        }
示例#21
0
        static void Main(string[] args)
        {
            Dog dog = new Dog();
            Cat cat = new Cat();
            Crocodile crocodile = new Crocodile();
            Shark shark = new Shark();
            Owl owl = new Owl();

            List<Animal> animals = new List<Animal>();
            animals.Add(dog);
            animals.Add(cat);
            animals.Add(crocodile);
            animals.Add(shark);
            animals.Add(owl);

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.Eat());
            }
            Console.WriteLine(dog.Greet());
        }
示例#22
0
        static void Main(string[] args)
        {
            Mammals m = new Mammals();
            Console.WriteLine(m.Move());
            Console.WriteLine(m.Greet());
            m = new Cat();
            Console.WriteLine(m.Move());
            Console.WriteLine(m.Greet());
            m = new Dog();
            Console.WriteLine(m.Move());
            Console.WriteLine(m.Greet());

            Console.WriteLine();

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

            Console.WriteLine();

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

            Console.WriteLine();

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

            Console.ReadKey();
        }
示例#23
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);
            }
        }
示例#24
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));
            }
        }
示例#25
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();
        }
示例#26
0
        public static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    var animal = Console.ReadLine();

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

                    var animaInfo = Console.ReadLine().Split(" ");

                    var name = animaInfo[0];
                    int age;
                    if (!int.TryParse(animaInfo[1], out age))
                    {
                        throw new ArgumentException("Invalid input!");
                    }
                    var gender = animaInfo[2];

                    if (animal == "Cat")
                    {
                        Console.WriteLine(animal);
                        Cat cat = new Cat(name, age, gender);
                        Console.WriteLine(cat);
                        cat.ProduceSound();
                    }
                    else if (animal == "Dog")
                    {
                        Console.WriteLine(animal);
                        Dog dog = new Dog(name, age, gender);
                        Console.WriteLine($"{dog}");
                        dog.ProduceSound();
                    }
                    else if (animal == "Frog")
                    {
                        Console.WriteLine(animal);
                        Frog frog = new Frog(name, age, gender);
                        Console.WriteLine(frog);
                        frog.ProduceSound();
                    }
                    else if (animal == "Kitten")
                    {
                        Console.WriteLine(animal);
                        Kitten kitten = new Kitten(name, age);
                        Console.WriteLine($"{kitten}");
                        kitten.ProduceSound();
                    }
                    else if (animal == "Tomcat")
                    {
                        Console.WriteLine(animal);
                        Tomcat tomcat = new Tomcat(name, age);
                        Console.WriteLine($"{tomcat}");
                        tomcat.ProduceSound();
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
示例#27
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));
            }
        }
示例#28
0
        public void Start()
        {
            /*Console.WriteLine("");
             * Console.WriteLine("Hello and welcome to our magnificent menagerie!");
             * Console.WriteLine("");
             * Console.WriteLine("May we introduce a fine bunch of animals for you?");
             * Console.WriteLine("y = Yes, please! n = Not right now, thank you!");
             * string input = Console.ReadLine();
             *  while (!(input == "y") && !(input == "n"))
             *  {
             *      Console.WriteLine("Please choose yes (y) or no (n)");
             *      input = Console.ReadLine();
             *  }
             *  if (input == "n")
             *  {
             *      Console.WriteLine("");
             *      Console.WriteLine("You're welcome to visit us at a more convenient time!");
             *      System.Environment.Exit(0);
             *  }
             *  else if (input == "y")
             *  {
             *      Console.WriteLine("");
             *      Console.WriteLine("Splendid! We have for you some tame animals (bird, dog, cat, pig and rat)");
             *      Console.WriteLine("... as well as some wild ones (bear, tiger and wolf).");
             *      Console.WriteLine("");
             *  }
             *
             * Console.WriteLine("Which animal would you like to meet?");
             * Console.WriteLine("1 = bird 2 = dog 3 = cat 4 = pig 5 = rat 6 = bear 7 = tiger 8 = wolf");
             * string input3 = Console.ReadLine();
             * Regex regex = new Regex("^(1|2|3|4|5|6|7|8)$");
             *
             * while (true)
             * {
             *  if (regex.IsMatch(input3))
             *  {
             *      Console.WriteLine("");
             *      Console.WriteLine("An excellent choice!");
             *      Console.WriteLine("");
             *      break;
             *  }
             *  else
             *  {
             *      Console.WriteLine("Unfortunately that option isn't available. Please choose one of the following: 1 = bird 2 = dog 3 = cat 4 = pig 5 = rat 6 = bear 7 = tiger 8 = wolf");
             *      input3 = Console.ReadLine();
             *  }
             * }
             *
             * if (input3 == "1")
             * {
             *  ITame bird = new Bird();
             * }
             *
             * while (true)
             * {
             *  Console.WriteLine("What would you like to do?");
             *  Regex regex2 = new Regex("^(0|1|2|3|4)$"); // if user chooses a tame animal
             *  if (regex2.IsMatch(input3))
             *  {
             *      Console.WriteLine("0 = Quit");
             *      Console.WriteLine("1 = Give the animal some food.");
             *      Console.WriteLine("2 = Give a name to the animal.");
             *      Console.WriteLine("3 = Call the animal to you.");
             *      Console.WriteLine("4 = Talk to the animal.");
             *
             *  }
             *  Regex regex3 = new Regex("^(5|6|7)$"); // if user chooses a wild animal
             *  if (regex3.IsMatch(input3))
             *  {
             *      Console.WriteLine("0 = Quit");
             *      Console.WriteLine("1 = See the animal hunt.");
             *      Console.WriteLine("2 = Hear what the animal sounds like.");
             *
             *  }
             *
             *  string input4 = Console.ReadLine();
             *
             *  if (input4 == "0")
             *  {
             *      Console.WriteLine("We're sorry to see you go! Please do stop by another time!");
             *      break;
             *  }
             *
             *  Regex regex4 = new Regex("^(1|2|3|4|)$");
             *
             *  if (!regex4.IsMatch(input4))
             *  {
             *      Console.WriteLine("Please choose one of the options above!");
             *  }
             *
             *  else if (regex4.IsMatch(input4))
             *  {
             *      if (Convert.ToInt32(input4) == 1)
             *      {
             *
             *      }
             *      if (Convert.ToInt32(input4) == 2)
             *      {
             *
             *      }
             *      if (Convert.ToInt32(input4) == 3)
             *      {
             *
             *      }
             *      if (Convert.ToInt32(input4) == 4)
             *      {
             *
             *      }
             *      if (Convert.ToInt32(input4) == 5)
             *      {
             *
             *      }
             *  }*/

            Console.WriteLine("");
            Console.WriteLine("Hello and welcome to our magnificent menagerie!");
            Console.WriteLine("");
            Console.WriteLine("May we introduce a fine bunch of animals for you?");
            Console.WriteLine("y = Yes, please! n = Not right now, thank you!");
            string input = Console.ReadLine();

            while (!(input == "y") && !(input == "n"))
            {
                Console.WriteLine("Please choose yes (y) or no (n)");
                input = Console.ReadLine();
            }
            if (input == "n")
            {
                Console.WriteLine("");
                Console.WriteLine("You're welcome to visit us at a more convenient time!");
                System.Environment.Exit(0);
            }
            if (input == "y")
            {
                Console.WriteLine("");
                Console.WriteLine("Splendid! We have for you some tame animals (bird, dog, cat, pig and rat)");
                Console.WriteLine("... as well as some wild ones (bear, tiger and wolf).");
                Console.WriteLine("");
            }

            while (true)
            {
                Console.WriteLine("Which animal would you like to meet?");
                Console.WriteLine();                                                                                        // added an empty line
                Console.WriteLine("0 = quit\n1 = Bird\n2 = Cat\n3 = Dog\n4 = Pig\n5 = Rat\n6 = Bear\n7 = Tiger\n8 = Wolf"); // changed Quit to quit
                string whichAnimal = Console.ReadLine();
                Regex  regexAnimal = new Regex("^(0|1|2|3|4|5|6|7|8|)$");
                if (!regexAnimal.IsMatch(whichAnimal))
                {
                    Console.WriteLine();
                    Console.WriteLine("Please choose one of the options above!");
                    Console.WriteLine();
                    System.Threading.Thread.Sleep(3000);
                    continue;
                }

                if (whichAnimal == "0")
                {
                    Console.WriteLine();
                    Console.WriteLine("We're sorry to see you go! Please do stop by another time!");
                    System.Threading.Thread.Sleep(3000);
                    break;
                }

                if (whichAnimal == "1")
                {
                    Bird bird = new Bird();
                    while (true)
                    {
                        Console.WriteLine("What would you like to do?");
                        Console.WriteLine(); // added an empty line to all

                        Console.WriteLine("1 = Go back.");
                        Console.WriteLine("2 = Give the animal some food.");
                        Console.WriteLine("3 = Give a name to the animal.");
                        Console.WriteLine("4 = Call the animal to you.");
                        Console.WriteLine("5 = Talk to the animal.");
                        string toDo = Console.ReadLine();

                        if (toDo != "1" && toDo != "2" && toDo != "3" && toDo != "4" && toDo != "5")
                        {
                            Console.WriteLine("Please choose one of the options above!");
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }

                        if (toDo == "1")
                        {
                            break;
                        }
                        if (toDo == "2")
                        {
                            Console.WriteLine();
                            bird.Eat();
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "3")
                        {
                            Console.WriteLine();
                            Console.WriteLine("What would you like to call the animal?");
                            string name = Console.ReadLine();
                            bird.GiveName(name);
                            Console.WriteLine();
                        }
                        if (toDo == "4")
                        {
                            Console.WriteLine();
                            Console.WriteLine(bird.ComeHere());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "5")
                        {
                            Console.WriteLine();
                            Console.WriteLine("What do you want to say to the animal?");
                            string something = Console.ReadLine();
                            Console.WriteLine();
                            Console.WriteLine(bird.MakeSound());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                    }
                }
                if (whichAnimal == "2")
                {
                    Cat cat = new Cat();
                    while (true)
                    {
                        Console.WriteLine("What would you like to do?");
                        Console.WriteLine();
                        Console.WriteLine("1 = Go back.");
                        Console.WriteLine("2 = Give the animal some food.");
                        Console.WriteLine("3 = Give a name to the animal.");
                        Console.WriteLine("4 = Call the animal to you.");
                        Console.WriteLine("5 = Talk to the animal.");
                        string toDo = Console.ReadLine();

                        if (toDo != "1" && toDo != "2" && toDo != "3" && toDo != "4" && toDo != "5")
                        {
                            Console.WriteLine("Please choose one of the options above!");
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }

                        if (toDo == "1")
                        {
                            break;
                        }
                        if (toDo == "2")
                        {
                            Console.WriteLine();
                            cat.Eat();
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "3")
                        {
                            Console.WriteLine();
                            Console.WriteLine("What would you like to call the animal?");
                            string name = Console.ReadLine();
                            cat.GiveName(name);
                            Console.WriteLine();
                        }
                        if (toDo == "4")
                        {
                            Console.WriteLine();
                            Console.WriteLine(cat.ComeHere());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "5")
                        {
                            Console.WriteLine();
                            Console.WriteLine("What do you want to say to the animal?");
                            string something = Console.ReadLine();
                            Console.WriteLine();
                            Console.WriteLine(cat.MakeSound());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                    }
                }
                if (whichAnimal == "3")
                {
                    Dog dog = new Dog();
                    while (true)
                    {
                        Console.WriteLine("What would you like to do?");
                        Console.WriteLine();
                        Console.WriteLine("1 = Go back.");
                        Console.WriteLine("2 = Give the animal some food.");
                        Console.WriteLine("3 = Give a name to the animal.");
                        Console.WriteLine("4 = Call the animal to you.");
                        Console.WriteLine("5 = Talk to the animal.");
                        string toDo = Console.ReadLine();

                        if (toDo != "1" && toDo != "2" && toDo != "3" && toDo != "4" && toDo != "5")
                        {
                            Console.WriteLine("Please choose one of the options above!");
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }

                        if (toDo == "1")
                        {
                            break;
                        }
                        if (toDo == "2")
                        {
                            Console.WriteLine();
                            dog.Eat();
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "3")
                        {
                            Console.WriteLine();
                            Console.WriteLine("What would you like to call the animal?");
                            string name = Console.ReadLine();
                            dog.GiveName(name);
                            Console.WriteLine();
                        }
                        if (toDo == "4")
                        {
                            Console.WriteLine();
                            Console.WriteLine(dog.ComeHere());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "5")
                        {
                            Console.WriteLine();
                            Console.WriteLine("What do you want to say to the animal?");
                            string something = Console.ReadLine();
                            Console.WriteLine();
                            Console.WriteLine(dog.MakeSound());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                    }
                }
                if (whichAnimal == "4")
                {
                    Pig pig = new Pig(); //CHANGE EVERYTHING FROM DOG TO PIG HERE (NOT CHANGE ALL OCCURRENCES)
                    while (true)
                    {
                        Console.WriteLine("What would you like to do?");
                        Console.WriteLine();
                        Console.WriteLine("1 = Go back.");
                        Console.WriteLine("2 = Give the animal some food.");
                        Console.WriteLine("3 = Give a name to the animal.");
                        Console.WriteLine("4 = Call the animal to you.");
                        Console.WriteLine("5 = Talk to the animal.");
                        string toDo = Console.ReadLine();

                        if (toDo != "1" && toDo != "2" && toDo != "3" && toDo != "4" && toDo != "5")
                        {
                            Console.WriteLine("Please choose one of the options above!");
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }

                        if (toDo == "1")
                        {
                            break;
                        }
                        if (toDo == "2")
                        {
                            Console.WriteLine();
                            pig.Eat();
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "3")
                        {
                            Console.WriteLine();
                            Console.WriteLine("What would you like to call the animal?");
                            string name = Console.ReadLine();
                            pig.GiveName(name);
                            Console.WriteLine();
                        }
                        if (toDo == "4")
                        {
                            Console.WriteLine();
                            Console.WriteLine(pig.ComeHere());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "5")
                        {
                            Console.WriteLine();
                            Console.WriteLine("What do you want to say to the animal?");
                            string something = Console.ReadLine();
                            Console.WriteLine();
                            Console.WriteLine(pig.MakeSound());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                    }
                }
                if (whichAnimal == "5")
                {
                    Rat rat = new Rat(); //CHANGE EVERYTHING FROM DOG TO RAT HERE (NOT CHANGE ALL OCCURRENCES)
                    while (true)
                    {
                        Console.WriteLine("What would you like to do?");
                        Console.WriteLine();
                        Console.WriteLine("1 = Go back.");
                        Console.WriteLine("2 = Give the animal some food.");
                        Console.WriteLine("3 = Give a name to the animal.");
                        Console.WriteLine("4 = Call the animal to you.");
                        Console.WriteLine("5 = Talk to the animal.");
                        string toDo = Console.ReadLine();

                        if (toDo != "1" && toDo != "2" && toDo != "3" && toDo != "4" && toDo != "5")
                        {
                            Console.WriteLine("Please choose one of the options above!");
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }

                        if (toDo == "1")
                        {
                            break;
                        }
                        if (toDo == "2")
                        {
                            Console.WriteLine();
                            rat.Eat();
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "3")
                        {
                            Console.WriteLine();
                            Console.WriteLine("What would you like to call the animal?");
                            string name = Console.ReadLine();
                            rat.GiveName(name);
                            Console.WriteLine();
                        }
                        if (toDo == "4")
                        {
                            Console.WriteLine();
                            Console.WriteLine(rat.ComeHere());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "5")
                        {
                            Console.WriteLine();
                            Console.WriteLine("What do you want to say to the animal?");
                            string something = Console.ReadLine();
                            Console.WriteLine();
                            Console.WriteLine(rat.MakeSound());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                    }
                }
                if (whichAnimal == "6")
                {
                    Bear bear = new Bear();
                    while (true)
                    {
                        Console.WriteLine("What would you like to do?");
                        Console.WriteLine();
                        Console.WriteLine("1 = Go back.");
                        Console.WriteLine("2 = Watch the animal hunt");
                        Console.WriteLine("3 = Hear the sound of the animal");
                        string toDo = Console.ReadLine();

                        if (toDo != "1" && toDo != "2" && toDo != "3")
                        {
                            Console.WriteLine("Please choose one of the options above!");
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }

                        if (toDo == "1")
                        {
                            break;
                        }
                        if (toDo == "2")
                        {
                            Console.WriteLine();
                            Console.WriteLine(bear.Hunt());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "3")
                        {
                            Console.WriteLine();
                            Console.WriteLine(bear.MakeSound());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                    }
                }
                if (whichAnimal == "7")
                {
                    Tiger tiger = new Tiger(); //CHANGE EVERYTHING FROM BEAR TO TIGER HERE (NOT CHANGE ALL OCCURRENCES)
                    while (true)
                    {
                        Console.WriteLine("What would you like to do?");
                        Console.WriteLine();
                        Console.WriteLine("1 = Go back.");
                        Console.WriteLine("2 = Watch the animal hunt");
                        Console.WriteLine("3 = Hear the sound of the animal");
                        string toDo = Console.ReadLine();

                        if (toDo != "1" && toDo != "2" && toDo != "3")
                        {
                            Console.WriteLine("Please choose one of the options above!");
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }

                        if (toDo == "1")
                        {
                            break;
                        }
                        if (toDo == "2")
                        {
                            Console.WriteLine();
                            Console.WriteLine(tiger.Hunt());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "3")
                        {
                            Console.WriteLine();
                            Console.WriteLine(tiger.MakeSound());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                    }
                }
                if (whichAnimal == "8")
                {
                    Wolf wolf = new Wolf(); //CHANGE EVERYTHING FROM BEAR TO WOLF HERE (NOT CHANGE ALL OCCURRENCES)
                    while (true)
                    {
                        Console.WriteLine("What would you like to do?");
                        Console.WriteLine();
                        Console.WriteLine("1 = Go back.");
                        Console.WriteLine("2 = Watch the animal hunt.");
                        Console.WriteLine("3 = Hear the sound of the animal.");
                        string toDo = Console.ReadLine();

                        if (toDo != "1" && toDo != "2" && toDo != "3")
                        {
                            Console.WriteLine("Please choose one of the options above!");
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }

                        if (toDo == "1")
                        {
                            break;
                        }
                        if (toDo == "2")
                        {
                            Console.WriteLine();
                            Console.WriteLine(wolf.Hunt());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                        if (toDo == "3")
                        {
                            Console.WriteLine();
                            Console.WriteLine(wolf.MakeSound());
                            Console.WriteLine();
                            System.Threading.Thread.Sleep(3000);
                        }
                    }
                }
            }
        }
 public void Bark()
 {
     Dog dog = new Dog();
     var response = dog.Bark(1);
     Assert.AreEqual(1, response.Count);
 }
示例#30
0
        static void Main()
        {
            var animal = Console.ReadLine();

            while (!animal.Equals("Beast!"))
            {
                try
                {
                    var animalInfo = Console.ReadLine()
                                     .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

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

                    switch (animal)
                    {
                    case "Dog":
                        var dog = new Dog(animalName, animalAge, animalGender);
                        Console.Write(dog);
                        dog.ProduceSound();
                        break;

                    case "Frog":
                        var frog = new Frog(animalName, animalAge, animalGender);
                        Console.Write(frog);
                        frog.ProduceSound();
                        break;

                    case "Cat":
                        var cat = new Cat(animalName, animalAge, animalGender);
                        Console.Write(cat);
                        cat.ProduceSound();
                        break;

                    case "Kitten":
                        var kitten = new Kitten(animalName, animalAge, "Female");
                        Console.Write(kitten);
                        kitten.ProduceSound();
                        break;

                    case "Tomcat":
                        var tomcat = new Tomcat(animalName, animalAge, "Male");
                        Console.Write(tomcat);
                        tomcat.ProduceSound();
                        break;

                    case "Animal":
                        Console.WriteLine("Not implemented!");
                        break;

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

                animal = Console.ReadLine();
            }
        }
示例#31
0
        public static void Main(string[] args)
        {
            var listOfAnimals = new List <Animal>();

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

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


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

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

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

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

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

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

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

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

                animalType = Console.ReadLine();

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

                animalTokens = Console.ReadLine()
                               .Split(";", StringSplitOptions.RemoveEmptyEntries);
            }
        }
示例#32
0
        public static void Main()
        {
            var dogs   = new Dictionary <string, Dog>();
            var cats   = new Dictionary <string, Cat>();
            var snakes = new Dictionary <string, Snake>();

            string input = Console.ReadLine();

            while (input != "I'm your Huckleberry")
            {
                string[] tokens = input.Split(' ');
                if (tokens.Length > 2)
                {
                    string animalClass = tokens[0];
                    string name        = tokens[1];
                    int    age         = int.Parse(tokens[2]);
                    int    parameter   = int.Parse(tokens[3]);

                    switch (animalClass)
                    {
                    case "Dog":
                        var newDog = new Dog()
                        {
                            Name         = name,
                            Age          = age,
                            NumberOfLegs = parameter
                        };

                        dogs.Add(newDog.Name, newDog);
                        break;

                    case "Cat":
                        var newCat = new Cat()
                        {
                            Name = name,
                            Age  = age,
                            IQ   = parameter
                        };

                        cats.Add(newCat.Name, newCat);
                        break;

                    case "Snake":
                        var newSnake = new Snake()
                        {
                            Name    = name,
                            Age     = age,
                            Cruelty = parameter
                        };

                        snakes.Add(newSnake.Name, newSnake);
                        break;
                    }
                }
                else
                {
                    string animalName = tokens[1];
                    if (dogs.ContainsKey(animalName))
                    {
                        dogs[animalName].ProduceSound();
                    }
                    else if (cats.ContainsKey(animalName))
                    {
                        cats[animalName].ProduceSound();
                    }
                    else
                    {
                        snakes[animalName].ProduceSound();
                    }
                }

                input = Console.ReadLine();
            }

            foreach (var dog in dogs)
            {
                Console.WriteLine("Dog: {0}, Age: {1}, Number of legs: {2}",
                                  dog.Key, dog.Value.Age, dog.Value.NumberOfLegs);
            }

            foreach (var cat in cats)
            {
                Console.WriteLine("Cat: {0}, Age: {1}, IQ: {2}",
                                  cat.Key, cat.Value.Age, cat.Value.IQ);
            }

            foreach (var snake in snakes)
            {
                Console.WriteLine("Snake: {0}, Age: {1}, Cruelty: {2}",
                                  snake.Key, snake.Value.Age, snake.Value.Cruelty);
            }
        }
示例#33
0
        public static void Main()
        {
            string inputLine = Console.ReadLine();

            Dictionary <string, Dog>   dogsList   = new Dictionary <string, Dog>();
            Dictionary <string, Cat>   catsList   = new Dictionary <string, Cat>();
            Dictionary <string, Snake> snakesList = new Dictionary <string, Snake>();

            while (!inputLine.Equals("I'm your Huckleberry"))
            {
                string[] inputTokens = inputLine.Split().ToArray();

                if (inputTokens.Length > 2)
                {
                    string animalType = inputTokens[0];
                    string name       = inputTokens[1];
                    int    age        = int.Parse(inputTokens[2]);
                    int    parameter  = int.Parse(inputTokens[3]);

                    switch (animalType)
                    {
                    case "Dog":
                        Dog newDog = new Dog
                        {
                            name         = name,
                            age          = age,
                            numberOfLegs = parameter
                        };

                        dogsList.Add(newDog.name, newDog);

                        break;

                    case "Cat":
                        Cat newCat = new Cat
                        {
                            name = name,
                            age  = age,
                            intelligenceQuotient = parameter
                        };

                        catsList.Add(newCat.name, newCat);
                        break;

                    case "Snake":
                        Snake newSnake = new Snake
                        {
                            name = name,
                            age  = age,
                            crueltyCoefficient = parameter
                        };

                        snakesList.Add(newSnake.name, newSnake);
                        break;
                    }
                }
                else
                {
                    string name = inputTokens[1];

                    if (dogsList.ContainsKey(name))
                    {
                        Console.WriteLine(dogsList[name].produceSound());
                    }
                    else if (catsList.ContainsKey(name))
                    {
                        Console.WriteLine(catsList[name].produceSound());
                    }
                    else if (snakesList.ContainsKey(name))
                    {
                        Console.WriteLine(snakesList[name].produceSound());
                    }
                }

                inputLine = Console.ReadLine();
            }

            foreach (var kvp in dogsList)
            {
                string name       = kvp.Key;
                Dog    currentDog = kvp.Value;

                Console.WriteLine("Dog: {0}, Age: {1}, Number Of Legs: {2}", currentDog.name, currentDog.age, currentDog.numberOfLegs);
            }

            foreach (var kvp in catsList)
            {
                string name       = kvp.Key;
                Cat    currentCat = kvp.Value;

                Console.WriteLine("Cat: {0}, Age: {1}, IQ: {2}", currentCat.name, currentCat.age, currentCat.intelligenceQuotient);
            }

            foreach (var kvp in snakesList)
            {
                string name         = kvp.Key;
                Snake  currentSnake = kvp.Value;

                Console.WriteLine("Snake: {0}, Age: {1}, Cruelty: {2}", currentSnake.name, currentSnake.age, currentSnake.crueltyCoefficient);
            }
        }
示例#34
0
        public static void Main()
        {
            var animal = new Dog("pesho", 22, "Male");

            Console.WriteLine(animal.ProduceSound());
        }
示例#35
0
        static void Main(string[] args)
        {
            string command = Console.ReadLine();

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

                    string name = input[0];
                    int    age  = 0;
                    if (!int.TryParse(input[1], out age))
                    {
                        Console.WriteLine("Invalid input!");
                        command = Console.ReadLine();
                        continue;
                    }
                    string gender = input[2];
                    switch (command.ToLower())
                    {
                    case "cat":
                        Cat cat = new Cat(name, age, gender);
                        Console.WriteLine(command);
                        Console.WriteLine(cat);
                        break;

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

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

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

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

                    default:
                        //Animal animal = new Animal(name, age, gender);
                        //Console.WriteLine(command);
                        Console.WriteLine("Invalid input!");
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }

                command = Console.ReadLine();
            }
        }
 public void BarkOncePerTreat()
 {
     Dog dog = new Dog();
     var response = dog.Bark(12);
     Assert.AreEqual(12, response.Count);
 }
 public void NoBarkNoTreats()
 {
     Dog dog = new Dog();
     var response = dog.Bark(0);
     Assert.AreEqual(0, response.Count);
 }
示例#38
0
文件: Engine.cs 项目: nadsit/Study
        public void Run()
        {
            string animalType = Console.ReadLine();

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

                    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());
            }
        }
示例#39
0
        static void Main(string[] args)
        {
            var inputCommand = Console.ReadLine();

            while (inputCommand != "Beast!")
            {
                var inputAnimalData = Console.ReadLine()
                                      .Split(new[] { ' ' });



                try
                {
                    var name = inputAnimalData[0];
                    if (!int.TryParse(inputAnimalData[1], out int age))
                    {
                        throw new ArgumentException("Invalid input!");
                    }
                    age = int.Parse(inputAnimalData[1]);
                    string gender = string.Empty;
                    if (inputAnimalData.Length == 3)
                    {
                        gender = inputAnimalData[2];
                    }

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

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

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

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

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

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

                inputCommand = Console.ReadLine();
            }
        }
        public static void Main()
        {
            var dogs   = new Dictionary <string, Dog>();
            var cats   = new Dictionary <string, Cat>();
            var snakes = new Dictionary <string, Snake>();


            string input = Console.ReadLine();

            while (input != "I'm your Huckleberry")
            {
                string[] parts = input.Split(' ');

                if (parts.Length > 2)
                {
                    string type      = parts[0];
                    string name      = parts[1];
                    int    age       = int.Parse(parts[2]);
                    int    parameter = int.Parse(parts[3]);

                    switch (type)
                    {
                    case "Dog":
                        Dog newDog = new Dog
                        {
                            Name         = name,
                            Age          = age,
                            NumberOfLegs = parameter
                        };

                        dogs.Add(newDog.Name, newDog);
                        break;

                    case "Cat":
                        Cat newCat = new Cat
                        {
                            Name = name,
                            Age  = age,
                            IntelligenceQuotient = parameter
                        };

                        cats.Add(newCat.Name, newCat);
                        break;

                    case "Snake":
                        Snake newSnake = new Snake
                        {
                            Name = name,
                            Age  = age,
                            CrueltyCoefficient = parameter
                        };

                        snakes.Add(newSnake.Name, newSnake);
                        break;
                    }
                }
                else
                {
                    string animalName = parts[1];

                    if (dogs.ContainsKey(animalName))
                    {
                        dogs[animalName].ProduceSound();
                    }
                    else if (cats.ContainsKey(animalName))
                    {
                        cats[animalName].ProduceSound();
                    }
                    else if (snakes.ContainsKey(animalName))
                    {
                        snakes[animalName].ProduceSound();
                    }
                }

                input = Console.ReadLine();
            }

            foreach (var dog in dogs.Values)
            {
                Console.WriteLine("Dog: {0}, Age: {1}, Number Of Legs: {2}", dog.Name, dog.Age, dog.NumberOfLegs);
            }

            foreach (var cat in cats.Values)
            {
                Console.WriteLine("Cat: {0}, Age: {1}, IQ: {2}", cat.Name, cat.Age, cat.IntelligenceQuotient);
            }

            foreach (var snake in snakes.Values)
            {
                Console.WriteLine("Snake: {0}, Age: {1}, Cruelty: {2}", snake.Name, snake.Age, snake.CrueltyCoefficient);
            }
        }
示例#41
0
        public static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();


            while (true)
            {
                var command = Console.ReadLine();

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

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

                try
                {
                    switch (command)
                    {
                    case "Dog":

                        Dog dog = new Dog(input[0], int.Parse(input[1]), input[2]);
                        animals.Add(dog);
                        break;

                    case "Cat":

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

                    case "Frog":

                        Frog frog = new Frog(input[0], int.Parse(input[1]), input[2]);
                        animals.Add(frog);
                        break;

                    case "Kitten":

                        Kitten kitten = new Kitten(input[0], int.Parse(input[1]));
                        animals.Add(kitten);
                        break;

                    case "Tomcat":

                        Tomcat tomcat = new Tomcat(input[0], int.Parse(input[1]));
                        animals.Add(tomcat);
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
示例#42
0
        public static void Main()
        {
            var inputLine = Console.ReadLine();

            List <Dog>   dogs   = new List <Dog>();
            List <Cat>   cats   = new List <Cat>();
            List <Snake> snakes = new List <Snake>();

            while (inputLine != "I'm your Huckleberry")
            {
                var tokens = inputLine.Split();

                if (tokens[0] != "talk")
                {
                    var animal = tokens[0];
                    var name   = tokens[1];
                    var age    = int.Parse(tokens[2]);
                    var param  = int.Parse(tokens[3]);

                    switch (animal)
                    {
                    case "Dog":
                        var dog = new Dog(name, age, param);
                        dogs.Add(dog);
                        break;

                    case "Cat":
                        var cat = new Cat(name, age, param);
                        cats.Add(cat);
                        break;

                    case "Snake":
                        var snake = new Snake(name, age, param);
                        snakes.Add(snake);
                        break;
                    }
                }
                else
                {
                    var currectName = tokens[1];

                    foreach (var dog in dogs)
                    {
                        if (dog.Name == currectName)
                        {
                            dog.ProduceSound();
                        }
                    }

                    foreach (var cat in cats)
                    {
                        if (cat.Name == currectName)
                        {
                            cat.ProduceSound();
                        }
                    }

                    foreach (var snake in snakes)
                    {
                        if (snake.Name == currectName)
                        {
                            snake.ProduceSound();
                        }
                    }
                }

                inputLine = Console.ReadLine();
            }

            foreach (var dog in dogs)
            {
                Console.WriteLine($"Dog: {dog.Name}, Age: {dog.Age}, Number Of Legs: {dog.NumberOfLegs}");
            }

            foreach (var cat in cats)
            {
                Console.WriteLine($"Cat: {cat.Name}, Age: {cat.Age}, IQ: {cat.IntelligenceQuotient}");
            }

            foreach (var snake in snakes)
            {
                Console.WriteLine($"Snake: {snake.Name}, Age: {snake.Age}, Cruelty: {snake.CrueltyCoefficient}");
            }
        }
示例#43
0
        static void Main(string[] args)
        {
            Cat siam = new Cat();

            siam.SetName("Miisu");
            siam.SetAge(13);
            siam.SetName("");
            siam.Name = "Miisu";
            siam.Age  = 13;

            Console.WriteLine("Kassi nimi on: " + siam.Age);
            Console.WriteLine("Kassi nimi on: " + siam.Name);
            Console.WriteLine("Kassi nimi on: " + siam.GetName());
            Console.WriteLine("Kassi vanus on: " + siam.GetAge());
            siam.Eat();
            siam.Drink();


            // siam.age = 2;

            Cat angora = new Cat();

            // angora.name = "Liisu";
            // angora.age = -270;
            angora.Drink();


            Dog buldog = new Dog();

            buldog.Name = "Pauk";
            buldog.Age  = 4;
            buldog.Eat();
            buldog.Drink();


            Toy         toy         = new Toy();
            Manufacture manufacture = new Manufacture();

            manufacture.Name   = "Disney";
            manufacture.Adress = "Kabi 2, Tartu";

            toy.Color       = "blue";
            toy.Manufacture = manufacture;
            toy.Model       = "hiir";
            toy.Name        = "Mikey";

            angora.FavoriteToy                  = toy;
            siam.FavoriteToy                    = toy;
            siam.FavoriteToy                    = new Toy();
            siam.FavoriteToy.Manufacture        = new Manufacture();
            siam.FavoriteToy.Model              = "Some model";
            siam.FavoriteToy.Name               = "Minni";
            siam.FavoriteToy.Manufacture.Name   = "Disney";
            siam.FavoriteToy.Manufacture.Adress = "Kabi 2, Tallinn, 12352";

            Cat persian = new Cat
            {
                Name        = "kity",
                Age         = 4,
                FavoriteToy = new Toy()
                {
                    Model = "Some model",
                    Name  = "Minni",

                    Manufacture = new Manufacture()
                    {
                        Adress = "Kabi 2, Tallinn, 12352",
                        Name   = "Disney"
                    }
                }
            };

            //persian.FavoriteToy.Manufacture = new Manufacture();
            //persian.FavoriteToy.Model = "Some model";
            //persian.FavoriteToy.Name = "Minni";
            //persian.FavoriteToy.Manufacture.Name = "Disney";
            //persian.FavoriteToy.Manufacture.Adress = "Kabi 2, Tallinn, 12352";



            Console.WriteLine("Kassi nimega {0}, lemmik manguasi on toodetud {1}  poot ja selle manguasi nimi on {2}", persian.Name, persian.FavoriteToy.Manufacture.Name, persian.FavoriteToy.Name);

            buldog.LastSwimmingTime = DateTime.Now;


            Console.WriteLine("Koer kais ujumas:{0}", buldog.LastSwimmingTime);

            DateTime dateTime = new DateTime(2017, 9, 7, 9, 17, 34);

            Console.WriteLine(dateTime);
            dateTime = dateTime.AddDays(2);
            dateTime = dateTime.AddHours(3);
            dateTime = dateTime.AddMinutes(5);
            Console.WriteLine(dateTime);

            Dog tax = new Dog();

            Console.WriteLine(tax.LastSwimmingTime);
            Dog dogi = new Dog("Naki", 4);

            Console.WriteLine(dogi.Name + " " + dogi.Age + " aastane");

            Dog retriver = new Dog(6, "Retriver");

            Console.WriteLine(retriver.Age + " " + retriver.Breed);
            retriver.Eat();
            Console.WriteLine();
            retriver.Eat(10);
            retriver.Eat(3, "fish");
            retriver.Eat(3, "Meat");



            Console.ReadLine();
        }
示例#44
0
        public static void Main()
        {
            List <Animal> animalCollection = new List <Animal>();
            string        input            = Console.ReadLine();

            while (input != "Beast!")
            {
                string[] tokens = Console.ReadLine().Split();
                try
                {
                    if (input == "Cat")
                    {
                        string name   = tokens[0];
                        int    age    = int.Parse(tokens[1]);
                        string gender = tokens[2];
                        Cat    cat    = new Cat(name, age, gender);
                        animalCollection.Add(cat);
                    }
                    else if (input == "Dog")
                    {
                        string name   = tokens[0];
                        int    age    = int.Parse(tokens[1]);
                        string gender = tokens[2];
                        Dog    dog    = new Dog(name, age, gender);
                        animalCollection.Add(dog);
                    }
                    else if (input == "Frog")
                    {
                        string name   = tokens[0];
                        int    age    = int.Parse(tokens[1]);
                        string gender = tokens[2];
                        Frog   frog   = new Frog(name, age, gender);
                        animalCollection.Add(frog);
                    }
                    else if (input == "Kitten")
                    {
                        string name    = tokens[0];
                        int    age     = int.Parse(tokens[1]);
                        Kitten kittens = new Kitten(name, age);
                        animalCollection.Add(kittens);
                    }
                    else if (input == "Tomcat")
                    {
                        string name   = tokens[0];
                        int    age    = int.Parse(tokens[1]);
                        Tomcat tomcat = new Tomcat(name, age);
                        animalCollection.Add(tomcat);
                    }
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }

                input = Console.ReadLine();
            }

            foreach (var animal in animalCollection)
            {
                Console.WriteLine(animal);
            }
        }
        static void Main(string[] args)
        {
            string        input   = Console.ReadLine();
            List <Animal> animals = new List <Animal>();

            while (input != "Beast!")
            {
                string   animalType       = input;
                string[] animalProperties = Console.ReadLine().Split();
                string   animalName       = animalProperties[0];
                int      animalAge        = int.Parse(animalProperties[1]);
                string   animalGender     = animalProperties[2];

                try
                {
                    switch (animalType.ToLower())
                    {
                    case "dog":
                        Dog dog = new Dog(animalName, animalAge, animalGender);
                        animals.Add(dog);
                        break;

                    case "cat":
                        Cat cat = new Cat(animalName, animalAge, animalGender);
                        animals.Add(cat);
                        break;

                    case "frog":
                        Frog frog = new Frog(animalName, animalAge, animalGender);
                        animals.Add(frog);
                        break;

                    case "kitten":
                        Kitten kitten = new Kitten(animalName, animalAge);
                        animals.Add(kitten);
                        break;

                    case "tomcat":
                        Tomcat tomcat = new Tomcat(animalName, animalAge);
                        animals.Add(tomcat);
                        break;

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


                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.GetType().Name);
                Console.WriteLine($"{animal.Name} {animal.Age} {animal.Gender}");
                animal.ProduceSound();
            }
        }
示例#46
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();

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

                string[] animalData = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   name       = animalData[0];
                int      age        = int.Parse(animalData[1]);
                string   gender     = animalData[2];

                Animal animal;
                switch (animalCommand)
                {
                case "Dog":
                    try
                    {
                        animal = new Dog(name, age, gender);
                        animals.Add(animal);
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "Cat":
                    try
                    {
                        animal = new Cat(name, age, gender);
                        animals.Add(animal);
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "Frog":
                    try
                    {
                        animal = new Frog(name, age, gender);
                        animals.Add(animal);
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "Kitten":
                    try
                    {
                        animal = new Kitten(name, age);
                        animals.Add(animal);
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "Tomcat":
                    try
                    {
                        animal = new Tomcat(name, age);
                        animals.Add(animal);
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                default:
                    continue;
                }
            }

            foreach (Animal animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
示例#47
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);
            }
        }