Inheritance: Animal
Exemple #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());
        }
Exemple #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));
        }
Exemple #3
0
        static void Main()
        {
            var scooby = new Dog("Scooby", 2, 'm');
            var frogy = new Frog("Frogy", 0.5, 'm');
            var tommy = new Cat("Tommy", 1, 'm');
            var kitty = new Kitten("Kitty", 0.8, 'f');
            var speedy = new Tomcat("Speedy", 1.5, 'f');
            var spark = new Dog("Spark", 3, 'm');
            var carmit = new Frog("Carmit", 1, 'm');
            var jenny = new Kitten("Jenny", 1.2, 'f');

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

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

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

            foreach (var animal in groupedAnimals)
            {
                Console.WriteLine("{0} - average age: {1:N2}", animal.GroupName.Name, animal.AverageAge);
            }
        }
        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));
        }
        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);
            }
        }
Exemple #6
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);
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
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);
 }
        static void Main(string[] args)
        {
            Cat cat = new Cat("Pesho",12, Gender.Male);
            Tomcat[] tomcats = new Tomcat[]
            {
                new Tomcat("Pesho",13),
                new Tomcat("Goshko",12),
                new Tomcat("Pencho",6),
                new Tomcat("Gencho",2)
            };

            Console.WriteLine("The average age of our tomcats is:{0}",Tomcat.AverageAge(tomcats));
        }
 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();
     }
 }
Exemple #11
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);
            }
        }
Exemple #13
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));
        }
Exemple #14
0
        static void Main(string[] args)
        {
            Animal[] animals = new Animal[5];
            animals[0]=new Cat("Mac",10,Gender.Male);
            animals[1]=new Kitten("Max",2);
            animals[2]=new Kitten("Missi",1);
            animals[3]=new Frog("Kermit",3,Gender.Male);
            animals[4]=new Frog("Tom",5,Gender.Male);
            animals.ToList();

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

             animals.GroupBy(t=>t.GetType().Name)
                .Select(group=>new {AnimalName=group.Key,AvarageAge=group.Average(a=>a.Age)})
                .ToList()
                .ForEach(group=>Console.WriteLine("{0}{1}",group.AnimalName,group.AvarageAge));
        }
        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());
        }
        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();
        }
Exemple #17
0
        static void Main(string[] args)
        {
            //test 
            Cat cat = new Cat(3, "Catty1", Sex.female);
            Console.WriteLine(cat.Name + " : " + cat.Age + " : " + cat.Sex);
            cat.MakeSound();
            Console.WriteLine();

            //make array of different kinds of animals
            Animal[] animals = {
                              new Kitten(2,"Kitty1"),
                              new Kitten(3,"Kitty2"),
                              new Tomcat(5,"Tommy1"),
                              new Tomcat(4,"Tommy2"),
                              new Frog(1,"Frog1",Sex.female),
                              new Frog(2,"Frog2",Sex.male),
                              new Frog(1,"Frog3",Sex.female),
                              new Cat(2,"",Sex.male),
                              cat,
                              new Cat(2,"Catty2",Sex.male),
                              new Dog(4,"Doggy1",Sex.male),
                              new Dog(6,"Doggy2",Sex.male)};

            // using LINQ to calculate the average age of each  
            // kind of animal in the array
            var averageAge = animals.GroupBy(x => x.GetType().Name)
                .Select(x => new
                {
                    Name = x.Key,
                    Average = x.Average(a => a.Age)
                })
                .ToList();

            foreach (var item in averageAge)
            {
                Console.WriteLine(String.Format("{0,-10}{1,2:0.0}",item.Name + " : ", item.Average));
            }
        }
Exemple #18
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();
        }
Exemple #19
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);
            }
        }
Exemple #20
0
        public static void Main(string[] args)
        {
            string input = Console.ReadLine();

            string[] animalArgs = Console.ReadLine().Split(' ');

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

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

                try
                {
                    switch (input)
                    {
                    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;
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                input = Console.ReadLine();

                if (input != "Beast!")
                {
                    animalArgs = Console.ReadLine().Split(' ');
                }
            }

            foreach (var Animal in animals)
            {
                Console.WriteLine(Animal);
            }
        }
        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();
            }
        }
Exemple #22
0
        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());
            }
        }
Exemple #23
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();
        }
Exemple #24
0
 public void SetDeadAndKiller(Cat killer)
 {
     this.weight = 0;
     this.killer = killer;
 }
Exemple #25
0
        public static void Main(string[] args)
        {
            string typeOfAnimal = Console.ReadLine();

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

            while (typeOfAnimal != "Beast!")
            {
                try
                {
                    string[] information = Console.ReadLine()
                                           .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                           .ToArray();
                    var name   = information[0];
                    var age    = int.Parse(information[1]);
                    var gender = string.Empty;

                    if (information.Length == 3)
                    {
                        gender = information[2];
                    }

                    if (typeOfAnimal == "Cat")
                    {
                        var cat = new Cat(name, age, gender);
                        animals.Add(cat);
                    }
                    else if (typeOfAnimal == "Dog")
                    {
                        var dog = new Dog(name, age, gender);
                        animals.Add(dog);
                    }
                    else if (typeOfAnimal == "Frog")
                    {
                        var frog = new Frog(name, age, gender);
                        animals.Add(frog);
                    }
                    else if (typeOfAnimal == "Kitten")
                    {
                        var kitten = new Kitten(name, age);
                        animals.Add(kitten);
                    }
                    else if (typeOfAnimal == "Tomcat")
                    {
                        var tomcat = new Tomcat(name, age);
                        animals.Add(tomcat);
                    }
                    else
                    {
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (Exception exeption)
                {
                    Console.WriteLine(exeption.Message);
                }
                typeOfAnimal = Console.ReadLine();
            }

            foreach (var aimal in animals)
            {
                Console.WriteLine(aimal);
            }
        }
        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);
                }
            }
        }
Exemple #27
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);
                        }
                    }
                }
            }
        }
Exemple #28
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);
            }
        }
        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();
            }
        }
Exemple #30
0
        public static void Main()
        {
            var animals = new List <Animal>();

            string command = String.Empty;

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

                try
                {
                    string name = String.Empty;

                    if (animalInfo.Length > 0)
                    {
                        name = animalInfo[0];
                    }

                    if (!int.TryParse(animalInfo[1], out int age))
                    {
                        throw new ArgumentException("Invalid input!");
                    }

                    string gender = string.Empty;

                    if (animalInfo.Length == 3)
                    {
                        gender = animalInfo[2];
                    }

                    command = command.ToLower();

                    if (command == "dog")
                    {
                        var animal = new Dog(name, age, gender);
                        animals.Add(animal);
                    }
                    else if (command == "cat")
                    {
                        var animal = new Cat(name, age, gender);
                        animals.Add(animal);
                    }
                    else if (command == "frog")
                    {
                        var animal = new Frog(name, age, gender);
                        animals.Add(animal);
                    }
                    else if (command == "kitten")
                    {
                        var animal = new Kitten(name, age);
                        animals.Add(animal);
                    }
                    else if (command == "tomcat")
                    {
                        var animal = new Tomcat(name, age);
                        animals.Add(animal);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
                Console.WriteLine($"{animal.ProduceSound()}");
            }
        }
Exemple #31
0
        public static void Main()
        {
            var animalType = String.Empty;

            while ((animalType = Console.ReadLine()) != "Beast!")
            {
                var args = Console.ReadLine()
                           .Split(' ');

                try
                {
                    switch (animalType)
                    {
                    case "Dog":
                    {
                        Animal animal = new Dog(args[0], int.Parse(args[1]), args[2]);
                        Console.WriteLine(animalType);
                        Console.WriteLine(animal);
                        break;
                    }

                    case "Frog":
                    {
                        Animal animal = new Frog(args[0], int.Parse(args[1]), args[2]);
                        Console.WriteLine(animalType);
                        Console.WriteLine(animal);
                        break;
                    }

                    case "Cat":
                    {
                        Animal animal = new Cat(args[0], int.Parse(args[1]), args[2]);
                        Console.WriteLine(animalType);
                        Console.WriteLine(animal);
                        break;
                    }

                    case "Kitten":
                    {
                        Animal animal = new Kitten(args[0], int.Parse(args[1]), args[2]);
                        Console.WriteLine(animalType);
                        Console.WriteLine(animal);
                        break;
                    }

                    case "Tomcat":
                    {
                        Animal animal = new Tomcat(args[0], int.Parse(args[1]), args[2]);
                        Console.WriteLine(animalType);
                        Console.WriteLine(animal);
                        break;
                    }

                    default: throw new ArgumentException("Invalid input!");
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }
        }
Exemple #32
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);
            }
        }
Exemple #33
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);
            }
        }
Exemple #34
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}");
            }
        }
Exemple #35
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);
            }
        }
        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);
            }
        }
        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());
            }
        }
Exemple #38
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();
            }
        }