static void Main() { Dog sharo = new Dog(3, "Sharo", Sex.Female); Frog pesho = new Frog(9, "Pesho", Sex.Female); Animal[] animals = { sharo, pesho }; Console.WriteLine(pesho.animalSound()); Console.WriteLine(Animal.AverageAge(animals)); }
private static Dog[] InstantiateDogs() { Dog[] dogs = new Dog[10]; for (int i = 0; i <= 5; i++) { dogs[i] = new Dog("Joe", 4, Sex.male, FurColour.black); } for (int i = 6; i < 10; i++) { dogs[i] = new Dog("Sharo", 13, Sex.female, FurColour.white); } return dogs; }
static void Main(string[] args) { List<Animal> userList = new List<Animal>(); userList.Add(new Dog(new Animal(3, "Pesho", true))); userList.Add(new Frog(new Animal(7, "Gosho", true))); userList.Add(new Kitten(new Cat(new Animal(2, "Minka", true)))); userList.Add(new Dog(new Animal(5, "Geri", true))); Animal.AverageAge(userList); Dog userDog = new Dog(new Animal(15, "Sasho", false)); userDog.MakeASound(); }
static void Main(string[] args) { Animal animal = new Cat("Mimi",4,Gender.female); Animal animal1 = new Dog("Sharo", 1, Gender.female); Animal animal2 = new Frog("Kikirica", 5, Gender.female); Animal animal3 = new Kitten("Mimi", 7); Animal animal4 = new Tomcat("Mimi", 5); Animal animal5 = new Frog("Mimi", 4, Gender.female); Animal[] zoo = new Animal[]{ animal,animal1,animal2,animal3,animal4,animal }; var avarageAge = zoo.Average(a=>a.Age); Console.WriteLine("{0:0.00}",avarageAge); }
static void Main() { Tomcat cat = new Tomcat("jonny", 4); Kitten cat2 = new Kitten("Holly", 2); Frog frog = new Frog("Jwey", 6, "male"); Dog dog = new Dog("Sharo", 3, "male"); cat.ProduceSound(); cat2.ProduceSound(); frog.ProduceSound(); dog.ProduceSound(); Animal[] animals = { cat, cat2, frog, dog, new Dog("Polly", 12, "female"), new Frog("Kolio", 2, "male"), new Tomcat("Nuni", 3), new Kitten("Loly", 9), new Frog("Josh", 1, "male"), new Kitten("Jenny", 5), new Dog("Bond", 5, "male"), new Tomcat("Josh", 14) }; var dogs = from animal in animals where animal is Dog select animal; var frogs = from animal in animals where animal is Frog select animal; var cats = from animal in animals where animal is Cat select animal; Console.WriteLine("Dogs avg age: " + ((double)dogs.Sum(a => a.Age)) / dogs.Count()); Console.WriteLine("Frogs avg age: " + ((double)frogs.Sum(a => a.Age)) / frogs.Count()); Console.WriteLine("Cats avg age: " + ((double)cats.Sum(a => a.Age)) / cats.Count()); }
static void Main() { //some tests Dog d = new Dog("Joe", 4, Sex.male, FurColour.black); d.MakeSound(); Console.WriteLine(d.GetSpecies()); d.Bite(); Console.WriteLine("----------------------"); Kitten k = new Kitten("Kittie", 5, 10, 10); k.MakeSound(); Console.WriteLine(k.GetSpecies()); k.SayAge(); k.Fight(); Console.WriteLine("----------------------"); Tomcat t = new Tomcat("Tommie", 3, 15, 25); Console.WriteLine(t.GetSpecies()); t.SayAge(); t.Fight(); t.MakeSound(); Console.WriteLine("----------------------"); Frog f = new Frog("Froggy", 1, Sex.male, 3); Console.WriteLine(f.GetSpecies()); Console.WriteLine("Froggy has {0} green spots", f.greenSpots); f.SayAge(); f.MakeSound(); Console.WriteLine("----------------------"); //instantiate arrays of dogs and tomcats Dog[] dogs = InstantiateDogs(); Tomcat[] tomcats = InstantiateTomcats(); //calculate average age Console.WriteLine("Average age of dogs: {0}", Animal.CalcAverageAge(dogs)); Console.WriteLine("Average age of tomcats: {0}", Animal.CalcAverageAge(tomcats)); }
public static void Main() { var input = Console.ReadLine(); var catsData = new Dictionary <string, Cat>(); var dogsData = new Dictionary <string, Dog>(); var snakesData = new Dictionary <string, Snake>(); while (input != "I'm your Huckleberry") { var animalData = input .Split() .ToArray(); if (animalData[0] != "talk") { if (animalData[0] == "Dog") { var currentDog = new Dog { Name = animalData[1], Age = int.Parse(animalData[2]), NumberOfLegs = int.Parse(animalData[3]) }; dogsData.Add(currentDog.Name, currentDog); } else if (animalData[0] == "Cat") { var currentCat = new Cat { Name = animalData[1], Age = int.Parse(animalData[2]), IntelligenceQuotient = int.Parse(animalData[3]) }; catsData.Add(currentCat.Name, currentCat); } else if (animalData[0] == "Snake") { var currentSnake = new Snake { Name = animalData[1], Age = int.Parse(animalData[2]), CrueltyCoefficient = int.Parse(animalData[3]) }; snakesData.Add(currentSnake.Name, currentSnake); } } else { var animalName = animalData[1]; foreach (var dog in dogsData.Keys) { if (dog == animalName) { Console.WriteLine(dogsData[dog].ProduceSound()); } } foreach (var cat in catsData.Keys) { if (cat == animalName) { Console.WriteLine(catsData[cat].ProduseSound()); } } foreach (var snake in snakesData.Keys) { if (snake == animalName) { Console.WriteLine(snakesData[snake].ProduseSound()); } } } input = Console.ReadLine(); } foreach (var dog in dogsData.Values) { Console.WriteLine(dog.Introduction()); } foreach (var cat in catsData.Values) { Console.WriteLine(cat.Introduction()); } foreach (var snake in snakesData.Values) { Console.WriteLine(snake.Introduction()); } }
static void Main(string[] args) { List <Dog> dogs = new List <Dog>(); List <Cat> cats = new List <Cat>(); List <Snake> snakes = new List <Snake>(); while (true) { var input = Console.ReadLine().Split(' '); if (input[0] == "I'm" && input[1] == "your" && input[2] == "Huckleberry") { break; } if (input.Length > 2) { var clas = input[0]; var nam = input[1]; var age = int.Parse(input[2]); var iq = int.Parse(input[3]); if (clas == "Dog") { var newDog = new Dog() { Name = nam, Age = age, NumberOfLegs = iq }; dogs.Add(newDog); } else if (clas == "Cat") { var newCat = new Cat() { Name = nam, Age = age, IntelligenceQuotient = iq }; cats.Add(newCat); } else if (clas == "Snake") { var newSnake = new Snake() { Name = nam, Age = age, CrueltyCoefficient = iq }; snakes.Add(newSnake); } } else { foreach (var dog in dogs) { if (input[1].Contains(dog.Name)) { Console.WriteLine("I'm a Distinguishedog, and I will now produce a distinguished sound! Bau Bau."); break; } } foreach (var cat in cats) { if (input[1].Contains(cat.Name)) { Console.WriteLine("I'm an Aristocat, and I will now produce an aristocratic sound! Myau Myau."); break; } } foreach (var snake in snakes) { if (input[1].Contains(snake.Name)) { Console.WriteLine("I'm a Sophistisnake, and I will now produce a sophisticated sound! Honey, I'm home."); } } } } 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}"); } }
static void Main() { Dictionary <string, Animal> animals = new Dictionary <string, Animal>(); List <Dog> dogs = new List <Dog>(); List <Cat> cats = new List <Cat>(); List <Snake> snakes = new List <Snake>(); string input = Console.ReadLine(); while (input != "I'm your Huckleberry") { string[] inputs = input.Split(' '); if (inputs[0] == "talk") { if (animals.ContainsKey(inputs[1])) { Animal a = animals[inputs[1]]; a.ProduceSound(); } } else { string className = inputs[0]; string name = string.Join(" ", inputs.Skip(1).Take(inputs.Length - 3)); int age = int.Parse(inputs.Skip(inputs.Length - 2).First()); int dependentFromClass = int.Parse(inputs.Skip(inputs.Length - 1).First()); switch (className) { case "Dog": Dog d = new Dog(name, age, dependentFromClass); animals.Add(name, d); dogs.Add(d); break; case "Snake": Snake s = new Snake(name, age, dependentFromClass); animals.Add(name, s); snakes.Add(s); break; case "Cat": Cat c = new Cat(name, age, dependentFromClass); animals.Add(name, c); cats.Add(c); break; } } input = 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.Iq}"); } foreach (var lady in snakes) { Console.WriteLine($"Snake: {lady.Name}, Age: {lady.Age}, Cruelty: {lady.CrueltyCoefficient}"); } }
public static void Main() { Dictionary <string, Dog> dogs = new Dictionary <string, Dog>(); Dictionary <string, Cat> cats = new Dictionary <string, Cat>(); Dictionary <string, Snake> snakes = new Dictionary <string, Snake>(); string inputLine = Console.ReadLine(); while (inputLine != "I'm your Huckleberry") { string[] tokens = inputLine.Split(' '); if (tokens.Length > 2) { string type = tokens[0]; string name = tokens[1]; int age = int.Parse(tokens[2]); int parameter = int.Parse(tokens[3]); switch (type) { case "Dog": Dog newDog = new Dog(); newDog.Name = name; newDog.Age = age; newDog.NumberOfLegs = parameter; dogs.Add(newDog.Name, newDog); break; case "Cat": Cat newCat = new Cat(); newCat.Name = name; newCat.Age = age; newCat.IntelligenceQuotient = parameter; cats.Add(newCat.Name, newCat); break; case "Snake": Snake newSnake = new Snake(); newSnake.Name = name; newSnake.Age = age; newSnake.CrueltyCoefficient = 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 if (snakes.ContainsKey(animalName)) { snakes[animalName].ProduceSound(); } } inputLine = Console.ReadLine(); } foreach (var dog in dogs.Values) { Console.WriteLine( $"Dog: {dog.Name}, Age: {dog.Age}, Number Of Legs: {dog.NumberOfLegs}"); } foreach (var cat in cats.Values) { Console.WriteLine( $"Cat: {cat.Name}, Age: {cat.Age}, IQ: {cat.IntelligenceQuotient}"); } foreach (var snake in snakes.Values) { Console.WriteLine( $"Snake: {snake.Name}, Age: {snake.Age}, Cruelty: {snake.CrueltyCoefficient}"); } }
public static void Main() { var dogs = new List <Dog>(); var cats = new List <Cat>(); var snakes = new List <Snake>(); var entered = Console.ReadLine(); while (entered != "I'm your Huckleberry") { var parameters = entered.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); var kind = parameters[0]; var name = parameters[1]; var age = string.Empty; var property = string.Empty;; if (parameters.Count > 2) { age = parameters[2]; property = parameters[3]; } if (kind == "Dog") { var newDog = new Dog(); { newDog.Class = kind; newDog.Name = name; newDog.Age = age; newDog.Legs = property; } dogs.Add(newDog); } else if (kind == "Cat") { var newCat = new Cat(); { newCat.Class = kind; newCat.Name = name; newCat.Age = age; newCat.IQ = property; } cats.Add(newCat); } else if (kind == "Snake") { var newSnake = new Snake(); { newSnake.Class = kind; newSnake.Name = name; newSnake.Age = age; newSnake.Cruelty = property; } snakes.Add(newSnake); } else { foreach (var item in dogs) { if (item.Name == name) { Console.WriteLine(Dog.ProduceSound()); } } foreach (var item in cats) { if (item.Name == name) { Console.WriteLine(Cat.ProduceSound()); } } foreach (var item in snakes) { if (item.Name == name) { Console.WriteLine(Snake.ProduceSound()); } } } entered = Console.ReadLine(); } foreach (var item in dogs) { Console.WriteLine($"{item.Class}: {item.Name}, Age: {item.Age}, Number Of Legs: {item.Legs}"); } foreach (var item in cats) { Console.WriteLine($"{item.Class}: {item.Name}, Age: {item.Age}, IQ: {item.IQ}"); } foreach (var item in snakes) { Console.WriteLine($"{item.Class}: {item.Name}, Age: {item.Age}, Cruelty: {item.Cruelty}"); } }
static void Main(string[] args) { Dog dog = new Dog("sharo", AnimalSex.male, 18); Console.WriteLine(dog.ToString()); Frog frog = new Frog("Kermit", AnimalSex.male, 20); Console.WriteLine(frog.ToString()); Cat regularCat = new Cat("CAT", AnimalSex.female, 4); Console.WriteLine(regularCat.ToString()); Kitten kitten = new Kitten("kittie", AnimalSex.female, 1); //Kitten kitten = new Kitten("kittie", AnimalSex.male, 1); - this will explode Console.WriteLine(kitten.ToString()); Tomcat tomcat = new Tomcat("Topcat", AnimalSex.male, 2); //Tomcat tomcat = new Tomcat("Topcat", AnimalSex.female, 2); - this too will explode Console.WriteLine(tomcat.ToString()); //sounds Console.WriteLine(); Console.WriteLine(dog.ProduceSound()); Console.WriteLine(frog.ProduceSound()); Console.WriteLine(regularCat.ProduceSound()); Console.WriteLine(kitten.ProduceSound()); Console.WriteLine(tomcat.ProduceSound()); Console.WriteLine(); List<Dog> dogs = new List<Dog>(); dogs.Add(dog); dogs.Add(new Dog("me4o", AnimalSex.female, 69)); dogs.Add(new Dog("FU", AnimalSex.female, 96)); double averageAge = dogs.Average((x) => x.Age); Console.WriteLine("Dogs average age: {0}", averageAge); List<Frog> frogs = new List<Frog>(); frogs.Add(frog); frogs.Add(new Frog("Big Toad", AnimalSex.male, 2)); frogs.Add(new Frog("Lesser Toad", AnimalSex.female, 2)); averageAge = frogs.Average((x) => x.Age); Console.WriteLine("Frogs average age: {0}", averageAge); List<Kitten> kittens = new List<Kitten>(); kittens.Add(kitten); kittens.Add(new Kitten("little kittenn", AnimalSex.female, 2)); kittens.Add(new Kitten("big kitten", AnimalSex.female, 2)); averageAge = kittens.Average((x) => x.Age); Console.WriteLine("Kittens average age: {0}", averageAge); }