using System; using System.Collections.Generic; using System.Text; namespace Lab1.Exercises.Register { class TaskUtils { public static int CountByGender(List dogs, Gender gender) { int count = 0; foreach (Dog dog in dogs) { if (dog.Gender.Equals(gender)) { count++; } } return count; } public static Dog FindOldestDog(List dogs) { Dog oldest = dogs[0]; // means least value for (int i = 1; i < dogs.Count; i++) { if (DateTime.Compare(dogs[i].BirthDate, oldest.BirthDate) < 0) { oldest = dogs[i]; } } return oldest; } public static List FindBreeds(List dogs) { List Breeds = new List(); foreach (Dog dog in dogs) { string breed = dog.Breed; if (!Breeds.Contains(breed)) // uses List method Contains() { Breeds.Add(breed); } } return Breeds; } public static List FilterByBreed(List dogs, string breed) { List Filtered = new List(); foreach (Dog dog in dogs) { if (dog.Breed.Equals(breed)) // uses string method Equals() { Filtered.Add(dog); } } return Filtered; } public static int CountByBreed(List dogs, string breed) { int count = 0; foreach (Dog dog in dogs) { if (dog.Breed.Equals(breed)) // uses string method Equals() { count++; } } return count; } public static List FindMostPopularBreeds(List dogs) { List breeds = FindBreeds(dogs); int mostPopularCount = CountByBreed(dogs, breeds[0]); foreach (string breed in breeds) { int count = CountByBreed(dogs, breed); if (count > mostPopularCount) { mostPopularCount = count; } } List popularBreeds = new List(); foreach (string breed in breeds) { if (CountByBreed(dogs, breed) == mostPopularCount) { popularBreeds.Add(breed); } } return popularBreeds; } } }