static void Main() { Kitten[] newKitten = new Kitten[5]; newKitten[0] = new Kitten("Lapichka", 5); newKitten[1] = new Kitten("Timiti", 1); newKitten[2] = new Kitten("Glezla", 3); newKitten[3] = new Kitten("Kotka", 2); newKitten[4] = new Kitten("Kitty", 10); Frog[] FrogsList = new Frog[3]; FrogsList[0] = new Frog("Kvak", 1, false); FrogsList[1] = new Frog("Skoklio", 1, true); FrogsList[2] = new Frog("Krasaveca", 3, false); Dog[] newDog = new Dog[4]; newDog[0] = new Dog("Rexy", 3, false); newDog[1] = new Dog("Tot", 4, false); newDog[2] = new Dog("Geya", 7, true); newDog[3] = new Dog("Ayay", 2, true); Console.WriteLine("Average age using standart calc: {0}", Animals.CalculateAverageLINQ(newKitten)); Console.WriteLine("Average age using LINQ calc: {0}", Animals.CalculateAverageLINQ(newDog)); Dog Sharo = new Dog("Sharo", 5, false); Console.WriteLine( "Sharo sais: " ); Sharo.MakeSound(); }
static void Main() { Dog[] dogs = new Dog[] { new Dog("Jaro", Animal.GenderValue.male,7), new Dog("Sharo", Animal.GenderValue.female, 3), new Dog("Doge", Animal.GenderValue.female,5), new Dog("Estel",Animal.GenderValue.male, 10) }; Frog[] frogs = new Frog[] { new Frog("Kikirica",Animal.GenderValue.male, 13), new Frog("Jaba", Animal.GenderValue.female,15), new Frog("Froggy",Animal.GenderValue.male, 5), new Frog("Nikoleta Lozanova",Animal.GenderValue.female, 10) }; Cat[] cats = new Cat[] { new Cat("Street Excellent",Animal.GenderValue.female, 3), new Cat("Home Excellent", Animal.GenderValue.female,5), new Cat("Persiiko", Animal.GenderValue.female,1), new Cat("Garfield",Animal.GenderValue.female,7) }; Kitten[] kittens = new Kitten[] { new Kitten("Malcho", 1), new Kitten("Palcho", 2), new Kitten("Shalco", 1) }; TomCat[] tomcats = new TomCat[] { new TomCat("Kotio", 5), new TomCat("Gosho", 4), new TomCat("Pesho", 8) }; double dogsAverageAge = Animal.AverageAge(dogs); double frogsAverageAge = Animal.AverageAge(frogs); double catsAverageAge = Animal.AverageAge(cats); double kittensAverageAge = Animal.AverageAge(kittens); double tomcatsAverageAge = Animal.AverageAge(tomcats); Console.WriteLine("Average age of the dogs: {0:F2}", dogsAverageAge); Console.WriteLine("Average age of the frogs: {0:F2}", frogsAverageAge); Console.WriteLine("Average age of the cats: {0:F2}", catsAverageAge); Console.WriteLine("Average age of the kittens: {0:F2}", kittensAverageAge); Console.WriteLine("Average age of the tomcats: {0:F2}", tomcatsAverageAge); Console.WriteLine(new string('-', 10)); Console.WriteLine("Sounds: "); cats[0].MakeSound(); dogs[1].MakeSound(); frogs[2].MakeSound(); }
static void Main() { string[] names = new string[] { "CALVIN", "CALYPSO", "CALZE", "FANCY", "FANNY", "FANTASIA", "MADDIE", "MADEIRA", "MADISON", "MADMAX", "FROGY" }; Random rand = new Random(); Animal[] cats = new Cat[12]; for (int i = 0; i < cats.Length; i++) { string name = names[rand.Next(0, 10)]; uint age = (uint)rand.Next(1, 10); SexType sex = (SexType)rand.Next(1, 3); Cat cat = new Cat(name, age); cat.Sex = sex; cats[i] = cat; } cats[10] = new Kitten("Kity", 1); cats[11] = new Tomcat("Big", 3); uint catsAverageAge = Animal.CalculateAverageAge(cats); Console.WriteLine("Cats average age: {0}" , catsAverageAge); Animal[] frogs = new Frog[3]; for (int i = 0; i < frogs.Length; i++) { string name = names[rand.Next(8, 11)]; uint age = (uint)rand.Next(1, 5); SexType sex = (SexType)rand.Next(1, 3); Frog frog = new Frog(name, age); frog.Sex = sex; frogs[i] = frog; } Console.WriteLine("Frogs make sound"); foreach (var frog in frogs) { frog.MakeSound(); Console.WriteLine("Wait"); } }
static void Main() { //Create arrays of different kinds of animals Animal[] animals = new Animal[5]; animals[0] = new Kitten("Kitty", 1); animals[1] = new Tomcat("Tom", 5); animals[2] = new Frog("Froggy"); animals[3] = new Frog("granny Frog", 6, Sex.Female); animals[4] = new Dog("Balkan", 4, Sex.Male); //test sound Console.WriteLine("Test sounds:"); Console.WriteLine(); foreach (var item in animals) { Console.WriteLine(item); Console.WriteLine(item.ProduceSound()); } Console.WriteLine(); //and calculate the average age of each kind of animal using a static method (you may use LINQ). var animalsAverageAgeByType = animals.GroupBy(a => a.GetType().Name) .Select(g => new { Kind = g.Key, AverageAge = g.Average(item => item.Age) }); Console.WriteLine("Average age of each kind of animal using a static method"); foreach (var item in animalsAverageAgeByType) { Console.WriteLine(item); } Console.WriteLine(); var animalsAverageAgeByTypeLINQ = from a in animals group a by a.GetType().Name into k select new { Kind = k.Key, AverageAge = k.Average(a => a.Age) }; Console.WriteLine("Average age of each kind of animal using LINQ"); foreach (var item in animalsAverageAgeByTypeLINQ) { Console.WriteLine(item); } Console.WriteLine(); }
static void Main() { Kitten penka = new Kitten("Penka", 1); Tomcat gosho = new Tomcat("Gosho", 5); Frog stamat = new Frog("Stamat", 1, AnimalGender.Male); Dog sharo = new Dog("Sharo", 15, AnimalGender.Male); Cat pisana = new Cat("Pisana", 3, AnimalGender.Female); List<Animal> animals = new List<Animal>() { penka, gosho, stamat, sharo, pisana }; foreach (var animal in animals) { Console.WriteLine(animal.ToString()); } Console.WriteLine(Animal.CalculateAverageAge(animals)); }
static void Main(string[] args) { Dog[] dogs = new Dog[] { new Dog("Sharo",5,'F'), new Dog("Mimi",3,'M'), new Dog("Becks",3.4,'F') }; Frog[] frogs = new Frog[] { new Frog("BiBI", 13, 'F'), new Frog("Katya", 15, 'M'), new Frog("Kolio", 5, 'M'), new Frog("Niki", 10, 'M') }; Cat[] cats = new Cat[] { new Cat("Ass", 3, 'F'), new Cat("Hand", 5, 'F'), new Cat("Head", 1, 'F'), new Cat("Leg", 7, 'M') }; Kitten[] kittens = new Kitten[] { new Kitten("Malcho", 1), new Kitten("Palcho", 2), new Kitten("Shalco", 1) }; Tomcat[] tomcats = new Tomcat[] { new Tomcat("Gosho", 5), new Tomcat("Mitko", 4), new Tomcat("Pesho", 8) }; Console.WriteLine("Average age of the dogs: {0:F2}", Animal.AverageAge(dogs)); Console.WriteLine("Average age of the frogs: {0:F2}",Animal.AverageAge(frogs)); Console.WriteLine("Average age of the cats: {0:F2}",Animal.AverageAge(cats)); Console.WriteLine("Average age of the kittens: {0:F2}", Animal.AverageAge(kittens)); Console.WriteLine("Average age of the tomcats: {0:F2}",Animal.AverageAge(tomcats)); }
static void Main(string[] args) { Dog[] dogs = new Dog[] { new Dog("Sharo", 5, 'F'), new Dog("Mimi", 3, 'M'), new Dog("Becks", 3.4, 'F') }; Frog[] frogs = new Frog[] { new Frog("BiBI", 13, 'F'), new Frog("Katya", 15, 'M'), new Frog("Kolio", 5, 'M'), new Frog("Niki", 10, 'M') }; Cat[] cats = new Cat[] { new Cat("Ass", 3, 'F'), new Cat("Hand", 5, 'F'), new Cat("Head", 1, 'F'), new Cat("Leg", 7, 'M') }; Kitten[] kittens = new Kitten[] { new Kitten("Malcho", 1), new Kitten("Palcho", 2), new Kitten("Shalco", 1) }; Tomcat[] tomcats = new Tomcat[] { new Tomcat("Gosho", 5), new Tomcat("Mitko", 4), new Tomcat("Pesho", 8) }; Console.WriteLine("Average age of the dogs: {0:F2}", Animal.AverageAge(dogs)); Console.WriteLine("Average age of the frogs: {0:F2}", Animal.AverageAge(frogs)); Console.WriteLine("Average age of the cats: {0:F2}", Animal.AverageAge(cats)); Console.WriteLine("Average age of the kittens: {0:F2}", Animal.AverageAge(kittens)); Console.WriteLine("Average age of the tomcats: {0:F2}", Animal.AverageAge(tomcats)); }
static void Main() { Kitten penka = new Kitten("Penka", 1); Tomcat gosho = new Tomcat("Gosho", 5); Frog stamat = new Frog("Stamat", 1, AnimalGender.Male); Dog sharo = new Dog("Sharo", 15, AnimalGender.Male); Cat pisana = new Cat("Pisana", 3, AnimalGender.Female); List <Animal> animals = new List <Animal>() { penka, gosho, stamat, sharo, pisana }; foreach (var animal in animals) { Console.WriteLine(animal.ToString()); } Console.WriteLine(Animal.CalculateAverageAge(animals)); }
static void Main(string[] args) { Frog[] frogs = new Frog[5]; frogs[0] = new Frog("Kermit", 7, "male"); frogs[1] = new Frog("Kikeriza", 7, "female"); frogs[2] = new Frog("Muholovka", 5, "female"); frogs[3] = new Frog("Purgavka", 3, "female"); frogs[4] = new Frog("Zelenko", 4, "female"); Dogs[] dogs = new Dogs[5]; dogs[0] = new Dogs("Sharo", 9, "male"); dogs[1] = new Dogs("Sharik", 11, "male"); dogs[2] = new Dogs("Murdjo", 7, "male"); dogs[3] = new Dogs("Minka", 10, "female"); dogs[4] = new Dogs("Lili", 8, "female"); Cats[] cats = new Cats[5]; cats[0] = new Kitten("Maca", 11); cats[1] = new Kitten("Puffi", 12); cats[2] = new TomCat("Chocho", 15); cats[3] = new TomCat("James", 10); cats[4] = new TomCat("Blacky", 17); var frogsAverageAge = frogs .Average(frog => frog.Age); var dogsAverageAge = dogs .Average(dog => dog.Age); var catsAverageAge = cats .Average(cat => cat.Age); Console.WriteLine("The average age of the frogs is {0}", frogsAverageAge.ToString()); Console.WriteLine(); Console.WriteLine("The average age of the dogs is {0}", dogsAverageAge.ToString()); Console.WriteLine(); Console.WriteLine("The average age of the cats is {0}", catsAverageAge.ToString()); Console.WriteLine(); }
//public static double AverageAge() //{ //} static void Main(string[] args) { Dog[] dogs = new Dog[2]; Dog d1 = new Dog("Bella", "female", 4); dogs[0] = d1; Dog d2 = new Dog("Dolly", "female", 8); dogs[1] = d2; PrintTheDogs(dogs); Console.WriteLine(); Frog[] frogs = new Frog[2]; Frog f1 = new Frog("Bulbasaur", "male", 3); frogs[0] = f1; Frog f2 = new Frog("Froggy", "female", 2); frogs[1] = f2; PrintTheFrogs(frogs); Console.WriteLine(); Cat[] cats = new Cat[2]; Cat c1 = new Cat("Tom", "male", 5); cats[0] = c1; Cat c2 = new Cat("Shatzi", "female", 4); cats[1] = c2; PrintTheCats(cats); Console.WriteLine(); Kitten[] kittens = new Kitten[1]; Kitten k1 = new Kitten("Lulu", "female", 1); PrintTheKittens(kittens); }
static void Main(string[] args) { #region Animals lists Kitten malkoKote = new Kitten(2, "Malko Kote"); Kitten poMalkoKote = new Kitten(1, "Po-malko kote"); Tomcat kitHarington = new Tomcat(2, "Kit Harington", true); Tomcat kitkat = new Tomcat(4, "KitKat", true); Frog boko = new Frog(5, "Boko", true); Frog kvako = new Frog(8, "Kvako", true); Cat felicia = new Cat(4, "Felicia", false); Cat penka = new Cat(10, "Penka", false); Dog cratos = new Dog(7, "Cratos", true); Dog sharo = new Dog(3, "sharo", true); List <Kitten> kittens = new List <Kitten> { malkoKote, poMalkoKote }; List <Tomcat> tomcats = new List <Tomcat> { kitHarington, kitkat }; List <Frog> frogs = new List <Frog> { boko, kvako }; List <Cat> cats = new List <Cat> { felicia, penka }; List <Dog> dogs = new List <Dog> { cratos, sharo }; #endregion #region Tests Console.WriteLine(dogs.AverageAge()); Console.WriteLine(cats.AverageAge()); Console.WriteLine(frogs.AverageAge()); Console.WriteLine(kittens.AverageAge()); Console.WriteLine(tomcats.AverageAge()); #endregion }
static void Main(string[] args) { Kitten kit = new Kitten("Kitty", 2); Tomcat tom = new Tomcat("Tom", 3); Frog leggy = new Frog("Leggy", 6, Gender.Male); Dog rex = new Dog("Rex", 4, Gender.Male); Cat snow = new Cat("Snow", 5, Gender.Female); List<Animal> animals = new List<Animal>() { kit, tom, leggy, rex, snow }; IntroduceAnimal(animals); Kitten[] kittens = new Kitten[] { kit, new Kitten("Lilly", 1), new Kitten("Smurf", 2) }; Tomcat[] tomcats = new Tomcat[] { tom, new Tomcat("Joefrrey", 3), new Tomcat("Steve", 2), new Tomcat("Paul", 1) }; Frog[] frogs = new Frog[] { leggy, new Frog("Squirrle", 12, Gender.Female), new Frog("Kurt", 1, Gender.Male) }; Dog[] dogs = new Dog[] { rex, new Dog("Fluffy", 4, Gender.Female), new Dog("Olde Doge", 12, Gender.Male) }; Cat[] cats = new Cat[] { snow }; Console.WriteLine("Kittens: {0:F2}", Animal.AverageAge(kittens)); Console.WriteLine("Tomcats: {0:F2}", Animal.AverageAge(tomcats)); Console.WriteLine("Frogs: {0:F2}", Animal.AverageAge(frogs)); Console.WriteLine("Dogs: {0:F2}", Animal.AverageAge(dogs)); Console.WriteLine("Cats: {0:F2}", Animal.AverageAge(cats)); }
static void Main(string[] args) { Frog Broasca1 = new Frog(1, "B1", "female"); Frog Broasca2 = new Frog(2, "B2", "female"); Frog Broasca3 = new Frog(3, "B3", "male"); Frog Broasca4 = new Frog(2, "B4", "female"); Frog[] Broaste = new[] { Broasca1, Broasca2, Broasca3, Broasca4 }; Dog Caine1 = new Dog(4, "C1", "male"); Dog Caine2 = new Dog(1, "C2", "male"); Dog Caine3 = new Dog(10, "C3", "female"); Dog Caine4 = new Dog(7, "C4", "female"); Dog[] Caini = new[] { Caine1, Caine2, Caine3, Caine4 }; Kitten Pisica1 = new Kitten(2, "P1", "female"); Kitten Pisica2 = new Kitten(6, "P2", "female"); Kitten Pisica3 = new Kitten(5, "P3", "female"); Kitten Pisica4 = new Kitten(1, "P4", "female"); Kitten[] Pisici = new[] { Pisica1, Pisica2, Pisica3, Pisica4 }; Tomcat Motan1 = new Tomcat(5, "M1", "male"); Tomcat Motan2 = new Tomcat(5, "M2", "male"); Tomcat Motan3 = new Tomcat(7, "M3", "male"); Tomcat Motan4 = new Tomcat(6, "M4", "male"); Tomcat[] Motani = new[] { Motan1, Motan2, Motan3, Motan4 }; AverageAgeOfAnimals.PrintBroasteAvaregeAge(Broaste); AverageAgeOfAnimals.PrintDogAvaregeAge(Caini); AverageAgeOfAnimals.PrintKittenAvaregeAge(Pisici); AverageAgeOfAnimals.PrintTomcatAvaregeAge(Motani); Console.ReadKey(); }
/*3. Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define useful constructors and methods. * Dogs, frogs and cats are Animals. * All animals can produce sound (specified by the ISound interface). * Kittens and tomcats are cats. * All animals are described by age, name and sex. * Kittens can be only female and tomcats can be only male. * Each animal produces a specific sound. * Create arrays of different kinds of animals and calculate the average age of each kind of animal using a static method (you may use LINQ).*/ static void Main() { //create different animals Cat cat = new Cat("Catty", 3, Sex.Female); Dog dog = new Dog("Silvestar", 5, Sex.Male); Frog froggy = new Frog("Froggy", 1, Sex.Female); Kitten kitten = new Kitten("Kitty", 5); Kitten kittenCat = new Kitten("Kety", 3); Tomcat tomcat = new Tomcat("Tom", 6); //produces a specific sound Console.Write("Cat make sound: "); cat.MakeSound(); Console.Write("Dog make sound: "); dog.MakeSound(); Console.Write("Frog make sound: "); froggy.MakeSound(); Console.WriteLine(); //Create arrays of different kinds of animals Animal[] animals = { cat, dog, froggy, kitten, tomcat, kittenCat}; foreach (var ani in animals) { Console.WriteLine(ani.ToString()); } //calculate the average age of all animals double agerageAgeOfAnimals = Animal.CalculateAverageAgeOfAnimals(animals); Console.WriteLine(); Console.WriteLine("Average age of all animals is {0:F3}", agerageAgeOfAnimals); //calculate the average age of each kind of animal Console.WriteLine("Average of each kind is: "); Animal.CalculateAverageAgeOfKind(animals); }
static void Main(string[] args) { Animal frog1 = new Frog("Jeremiah", "Male", 8); Animal frog2 = new Frog("Kermit", "Female", 9); Animal frog3 = new Frog("Lollihops", "Male", 8); Animal frog4 = new Frog("Ribbit", "Male", 11); Animal cat1 = new Cat("Leo", "Male", 10); Animal cat2 = new Cat("Milo", "Female", 3); Animal cat3 = new Cat("Ollie", "Male", 7); Animal kitten1 = new Kitten("Oreo", 8); Animal kitten2 = new Kitten("Winston", 5); Animal dog1 = new Dog("Bailey", "Male", 8); Animal dog2 = new Dog("Kobe", "Female", 16); List<Animal> listAnimals = new List<Animal>(); listAnimals.AddRange(new List<Animal>() { frog1, frog2, frog3, frog4, cat1, cat2, cat3, kitten1, kitten2, dog1, dog2 }); Console.WriteLine(Animal.CalculateAverage(listAnimals, typeof(Dog).ToString())); }
static void Main(string[] args) { var d1 = new Dog("Beagle", 3, "male"); d1.Print(); var d2 = new Dog("Labrador", 6, "female"); d2.Print(); var f1 = new Frog("Broscuta", 1, "female"); f1.Print(); var c1 = new Cat("Pisica", 2, "female"); c1.Print(); var k1 = new Kitten("Kitten", 4); ((Cat)k1).Print(); k1.Gender = "male"; ((Cat)k1).Print(); var t1 = new Tomcat("Tomcat", 5); t1.Age = 20; ((Cat)t1).Print(); Console.WriteLine("-----------------------------------------"); Console.WriteLine($"Average age of all animals: {Animal.GetAverageAgeAnimals().ToString("#.##")}"); Console.WriteLine($"Average age of all dogs: {Dog.GetAverageAgeDogs().ToString("#.##")}"); Console.WriteLine($"Average age of all frogs: {Frog.GetAverageAgeFrogs().ToString("#.##")}"); Console.WriteLine($"Average age of all cats: {Cat.GetAverageAgeCats().ToString("#.##")}"); Console.ReadKey(); }
public static void Main() { Cat[] cats = new Cat[] { new Cat("Jonny", 1, Sex.male), new Cat("Hue", 2, Sex.male), new Cat("Maia", 2, Sex.female), }; Dog[] dogs = new Dog[] { new Dog("Ivo", 5, Sex.male), new Dog("Pesho", 4, Sex.male), new Dog("Maria", 8, Sex.female), }; Frog[] frogs = new Frog[] { new Frog("Gosho", 4, Sex.male), new Frog("Ivan", 5, Sex.female), new Frog("Zahari", 3, Sex.male) }; Kitten[] kittens = new Kitten[] { new Kitten("Mihaela", 5), new Kitten("Ivona", 3), new Kitten("Petra", 2) }; Tomcat[] tomcats = new Tomcat[] { new Tomcat("Rado", 3), new Tomcat("Radoi", 3), new Tomcat("Frodo", 2) }; Console.WriteLine("Cats average age is: "); Console.WriteLine("{0:F2}", Cat.AverageAge(cats)); Console.WriteLine("The cat say: {0}", cats[0].Sound()); Console.WriteLine(); Console.WriteLine("Cats average age is: "); Console.WriteLine("{0:F2}", Dog.AverageAge(dogs)); Console.WriteLine("The cat say: {0}", dogs[0].Sound()); Console.WriteLine(); Console.WriteLine("Cats average age is: "); Console.WriteLine("{0:F2}", Frog.AverageAge(frogs)); Console.WriteLine("The cat say: {0}", frogs[0].Sound()); Console.WriteLine(); Console.WriteLine("Cats average age is: "); Console.WriteLine("{0:F2}", Kitten.AverageAge(kittens)); Console.WriteLine("The cat say: {0}", kittens[0].Sound()); Console.WriteLine(); Console.WriteLine("Cats average age is: "); Console.WriteLine("{0:F2}", Tomcat.AverageAge(tomcats)); Console.WriteLine("The cat say: {0}", tomcats[0].Sound()); }
static void Main() { Dog dog = new Dog("Dark", 5, true); Console.WriteLine(dog); Frog frog = new Frog("Jaburana", 3, false); Console.WriteLine(frog); Kitten kitten = new Kitten("Pisana", 2); Console.WriteLine(kitten); Tomcat tomcat = new Tomcat("Tom", 2); Console.WriteLine(tomcat); Dog[] dogs = new Dog[] { new Dog("Dark", 2, true), new Dog("Mark", 1, true), new Dog("Vark", 2, true), new Dog("Lara", 3, false) }; Frog[] frogs = new Frog[] { new Frog("Jaburan4o", 1, true), new Frog("Jab4o", 2, true), new Frog("Jaja", 4, false), new Frog("Jaburana", 4, false), }; Cat[] cats = new Cat[] { new Cat("Street Excellent", 3, false), new Cat("Home Excellent", 5, false), new Cat("Persiiko", 1, true), new Cat("Garfield", 7, true) }; Kitten[] kittens = new Kitten[] { new Kitten("Pisana", 3), new Kitten("Pis", 10), new Kitten("Pisun", 6), new Kitten("Pissss", 2), new Kitten("MacPis", 4), }; Tomcat[] tomcats = new Tomcat[] { new Tomcat("Kotio", 5), new Tomcat("Gosho", 4), new Tomcat("Pesho", 8) }; double dogsAverageAge = dogs.Average(x => x.Age); double frogAverageAge = frogs.Average(x => x.Age); double catAverageAge = cats.Average(x => x.Age); Console.WriteLine(dogsAverageAge); Console.WriteLine(frogAverageAge); Console.WriteLine(catAverageAge); //или с метод в Animal //double dogsAverageAge = Animal.AverageAge(dogs); }
public Frog(Frog frog) : base((Animal)frog) { }
/* * 3. Animal hierarchy * * Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define useful constructors and methods. Dogs, frogs and cats are Animals. * All animals can produce sound (specified by the ISound interface). Kittens and tomcats are cats. All animals are described by age, * name and sex. Kittens can be only female and tomcats can be only male. Each animal produces a specific sound. * Create arrays of different kinds of animals and calculate the average age of each kind of animal using a static method (you may use LINQ). * */ static void Main() { var arrWithCats = new Cat[] { new Cat(14, "Gosho", Sex.Male), new Cat(6, "Mialcho", Sex.Male), new Cat(10, "Misha", Sex.Female), new Cat(9, "Joystick", Sex.Male), new Cat(14, "Macka", Sex.Female) }; Console.ForegroundColor = ConsoleColor.Magenta; foreach (var item in arrWithCats) { Console.WriteLine(item.ProduceSount()); } Console.WriteLine("Average ange of all cats : " + Animal.AverageAge(arrWithCats) + "\n"); var arrWithKittens = new Kitten[] { new Kitten(2, "Peshka"), new Kitten(1, "Mimka"), new Kitten(3, "Dimitrinka"), new Kitten(1, "Skilitka") }; Console.ForegroundColor = ConsoleColor.Cyan; foreach (var item in arrWithKittens) { Console.WriteLine(item.ProduceSount()); } Console.WriteLine("Average ange of all kittens : " + Animal.AverageAge(arrWithKittens) + "\n"); var arrWithTomcats = new Tomcat[] { new Tomcat(1, "Stamatcho"), new Tomcat(2, "Metadoncho"), new Tomcat(1, "Ivelincho"), }; Console.ForegroundColor = ConsoleColor.Blue; foreach (var item in arrWithTomcats) { Console.WriteLine(item.ProduceSount()); } Console.WriteLine("Average ange of all tomcats : " + Animal.AverageAge(arrWithTomcats) + "\n"); var arrWithDogs = new Dog[] { new Dog(1, "Sharo", Sex.Male), new Dog(2, "Pincho", Sex.Male), new Dog(3, "Kalina", Sex.Female), new Dog(4, "Steven", Sex.Male), new Dog(5, "MIla", Sex.Female), }; Console.ForegroundColor = ConsoleColor.Yellow; foreach (var item in arrWithDogs) { Console.WriteLine(item.ProduceSount()); } Console.WriteLine("Average ange of all dogs : " + Animal.AverageAge(arrWithDogs) + "\n"); var arrWithFrogs = new Frog[] { new Frog(1, "Japcho", Sex.Male), new Frog(2, "Kwa", Sex.Male), new Frog(3, "Japka", Sex.Female), new Frog(4, "Jaburan", Sex.Male), new Frog(5, "Roberta", Sex.Female), }; Console.ForegroundColor = ConsoleColor.Green; foreach (var item in arrWithFrogs) { Console.WriteLine(item.ProduceSount()); } Console.WriteLine("Average ange of all frogs : " + Animal.AverageAge(arrWithFrogs) + "\n"); }
static void Main() { Kitten maca = new Kitten("Maca", 1); Cat tomas = new Cat("Tomas", 5, Gender.male); Dog sharo = new Dog("Sharo", 5, Gender.male); Frog kroko = new Frog("Kroko", 3, Gender.male); Tomcat herkules = new Tomcat("Herkules", 20); List<Kitten> kittens = new List<Kitten>() { maca, new Kitten("Pisi", 2), new Kitten("Lapa", 1) }; Cat[] cats = new Cat[] { tomas, new Cat("Gosho", 4, Gender.male), new Cat("Sara", 8, Gender.female), new Cat("Pesho", 11, Gender.male) }; Dog[] dogs = new Dog[] { sharo, new Dog("Chocho", 16, Gender.male), new Dog("Lucky", 8, Gender.female), new Dog("Sara", 10, Gender.female) }; List<Frog> frogs = new List<Frog>() { kroko, new Frog("Kroki", 2, Gender.female) }; Tomcat[] tomcats = new Tomcat[] { herkules, new Tomcat("Paul", 11), new Tomcat("Richard", 9) }; Console.WriteLine("Average ages of animals in collections:"); Console.WriteLine(string.Format("Tomcats: {0:F2}",Animal.AvgAge(tomcats))); Console.WriteLine(string.Format("Kittens: {0:F2}", Animal.AvgAge(kittens))); Console.WriteLine(string.Format("Cats: {0:F2}",Animal.AvgAge(cats))); Console.WriteLine(string.Format("Dogs: {0:F2}", Animal.AvgAge(dogs))); Console.WriteLine(string.Format("Frogs: {0:F2}", Animal.AvgAge(frogs))); Console.WriteLine("\nSounds the animals make:"); Console.Write("Kitten: "); maca.MakeSound(); Console.Write("Tomcat: "); herkules.MakeSound(); Console.Write("Cat: "); tomas.MakeSound(); Console.Write("Dog: "); sharo.MakeSound(); Console.Write("Frog: "); kroko.MakeSound(); }
static void Main() { // Testing all classes and printing the average age of each group of animals Console.WriteLine("TESTING ALL CLASSES AND THE AVERAGE AGE METHOD ON THEM:"); Cat[] cats = new Cat[] { new Cat("Pissy", 3, "Female"), new Cat("Missy", 7, "Female"), new Cat("Tommy", 11, "Male") }; Console.WriteLine("The average age of the cats is: {0:F2} years.", AverageAge(cats)); Dog[] dogs = new Dog[] { new Dog("Timmy", 8, "Male"), new Dog("Gabby", 4, "Female"), new Dog("Jake", 13, "Male") }; Console.WriteLine("The average age of the dogs is: {0:F2} years.", AverageAge(dogs)); Frog[] frogs = new Frog[] { new Frog("Josh", 1, "Male", "Blue"), new Frog("Patricia", 7, "Female", "Green"), new Frog("Helen", 6, "Female", "Black") }; Console.WriteLine("The average age of the frogs is: {0:F2} years.", AverageAge(frogs)); Tomcat[] tomcats = new Tomcat[] { new Tomcat("Billy", 5), new Tomcat("Oliver", 3), new Tomcat("Sully", 2), new Tomcat("Lefty", 1) }; Console.WriteLine("The average age of the tomcats is: {0:F2} years.", AverageAge(tomcats)); Kitten[] kittens = new Kitten[] { new Kitten("Mandy", 3), new Kitten("Suzy", 6), new Kitten("Mary", 2), new Kitten("Dolly", 5) }; Console.WriteLine("The average age of the kittens is: {0:F2} years.", AverageAge(kittens)); Console.WriteLine(); // Testing the Breed property and the Gender property Console.WriteLine("TESTING THE BREED PROPERTY AND THE GENDER PROPERTY:"); dogs[2].Breed = "Golden retriever"; Console.WriteLine("{0} is a dog. It's breed is {1} and it's gender is {2}.", dogs[2].Name, dogs[2].Breed, dogs[2].Gender); cats[1].Breed = "Persian"; Console.WriteLine("{0} is a cat. It's breed is {1} and it's gender is {2}.", cats[1].Name, cats[1].Breed, cats[1].Gender); tomcats[1].Breed = "Siberian"; Console.WriteLine("{0} is a tomcat. It's breed is {1} and it's gender is {2}.", tomcats[1].Name, tomcats[1].Breed, tomcats[1].Gender); kittens[0].Breed = "Siamese"; Console.WriteLine("{0} is a kitten. It's breed is {1} and it's gender is {2}.", kittens[0].Name, kittens[0].Breed, kittens[0].Gender); Console.WriteLine(); // Testing the optional methods, that I added Console.WriteLine("TESTING THE OPTIONAL METHODS:"); Console.WriteLine(cats[0].Eat()); Console.WriteLine(dogs[0].Fetch()); Console.WriteLine(frogs[0].Hop()); Console.WriteLine(tomcats[0].Hunt()); Console.WriteLine(kittens[0].Sleep()); Console.WriteLine(); // Testing class Animal and calculating the average age of the different animals in the array Animal[] animals = new Animal[5]; animals[0] = cats[0]; animals[1] = dogs[1]; animals[2] = frogs[2]; animals[3] = tomcats[3]; animals[4] = kittens[3]; Console.WriteLine("TESTING THE AVERAGE AGE METHOD ON AN ARRAY OF DIFFERENT ANIMALS:"); Console.WriteLine("The average age of the animals is: {0:F2} years.", AverageAge(animals)); Console.WriteLine(); // Testing the MakeSound method for every animal Console.WriteLine("TESTING THE MAKESOUND METHOD ON EVERY CLASS:"); foreach (var animal in animals) { Console.WriteLine("The {0} makes that sound \"{1}\"", animal.ToString().Substring(16).ToLower(), animal.MakeSound()); } Console.WriteLine(); }
public static void Main() { Cat[] cats = new Cat[] { new Cat("Jonny", 1, Sex.male), new Cat("Hue", 2, Sex.male), new Cat("Maia", 2, Sex.female), }; Dog[] dogs = new Dog[] { new Dog("Ivo", 5, Sex.male), new Dog("Pesho", 4, Sex.male), new Dog("Maria", 8, Sex.female), }; Frog[] frogs = new Frog[] { new Frog("Gosho", 4, Sex.male), new Frog("Ivan", 5, Sex.female), new Frog("Zahari", 3, Sex.male) }; Kitten[] kittens = new Kitten[] { new Kitten("Mihaela", 5), new Kitten("Ivona", 3), new Kitten("Petra", 2) }; Tomcat[] tomcats = new Tomcat[] { new Tomcat("Rado", 3), new Tomcat("Radoi", 3), new Tomcat("Frodo", 2) }; Console.WriteLine("Cats average age is: "); Console.WriteLine("{0:F2}", Cat.AverageAge(cats)); Console.WriteLine("The cat say: {0}", cats[0].Sound()); Console.WriteLine(); Console.WriteLine("Cats average age is: "); Console.WriteLine("{0:F2}", Dog.AverageAge(dogs)); Console.WriteLine("The cat say: {0}", dogs[0].Sound()); Console.WriteLine(); Console.WriteLine("Cats average age is: "); Console.WriteLine("{0:F2}", Frog.AverageAge(frogs)); Console.WriteLine("The cat say: {0}", frogs[0].Sound()); Console.WriteLine(); Console.WriteLine("Cats average age is: "); Console.WriteLine("{0:F2}", Kitten.AverageAge(kittens)); Console.WriteLine("The cat say: {0}", kittens[0].Sound()); Console.WriteLine(); Console.WriteLine("Cats average age is: "); Console.WriteLine("{0:F2}", Tomcat.AverageAge(tomcats)); Console.WriteLine("The cat say: {0}", tomcats[0].Sound()); }
/* Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define useful constructors and methods. Dogs, frogs and cats are Animals. All animals can produce sound (specified by the ISound interface). Kittens and tomcats are cats. All animals are described by age, name and sex. Kittens can be only female and tomcats can be only male. Each animal produces a specific sound. Create arrays of different kinds of animals and calculate the average age of each kind of animal using a static method (you may use LINQ). */ public static void Main() { Dog[] dogs = new Dog[] { new Dog("Jaro", 7, true, "Golden Retriever"), new Dog("Sharo", 3, true, "German Sheperd"), new Dog("Doge", 5, true, "Labrador Retriever"), new Dog("Estel", 10, false, "Pincher") }; Frog[] frogs = new Frog[] { new Frog("Kikirica", 13, false), new Frog("Jaba", 15, false), new Frog("Froggy", 5, true), new Frog("Nikoleta Lozanova", 10, false) }; Cat[] cats = new Cat[] { new Cat("Street Excellent", 3, false), new Cat("Home Excellent", 5, false), new Cat("Persiiko", 1, true), new Cat("Garfield", 7, true) }; Kitten[] kittens = new Kitten[] { new Kitten("Malcho", 1), new Kitten("Palcho", 2), new Kitten("Shalco", 1) }; Tomcat[] tomcats = new Tomcat[] { new Tomcat("Kotio", 5), new Tomcat("Gosho", 4), new Tomcat("Pesho", 8) }; double dogsAverageAge = Animal.AverageAge(dogs); double frogsAverageAge = Animal.AverageAge(frogs); double catsAverageAge = Animal.AverageAge(cats); double kittensAverageAge = Animal.AverageAge(kittens); double tomcatsAverageAge = Animal.AverageAge(tomcats); Console.WriteLine("Average age of the dogs: {0:F2}", dogsAverageAge); Console.WriteLine("Average age of the frogs: {0:F2}", frogsAverageAge); Console.WriteLine("Average age of the cats: {0:F2}", catsAverageAge); Console.WriteLine("Average age of the kittens: {0:F2}", kittensAverageAge); Console.WriteLine("Average age of the tomcats: {0:F2}", tomcatsAverageAge); Console.WriteLine(new string('-', 10)); Console.WriteLine("Actions: "); Console.WriteLine(tomcats[0].Hunt()); Console.WriteLine((cats[1].BeGracious())); Console.WriteLine(dogs[2].Fetch()); Console.WriteLine(frogs[1].JumpAround()); Console.WriteLine(new string('-', 10)); Console.WriteLine("Sounds: "); cats[0].MakeSound(); dogs[1].MakeSound(); frogs[2].MakeSound(); }