Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace AlgorithmsRetakeExam
- {
- public class Hotel
- {
- private string name;
- private List<Dog> dogs;
- public Hotel()
- {
- }
- public Hotel(string name)
- {
- Name = name;
- Dogs = new List<Dog>();
- }
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }
- public List<Dog> Dogs
- {
- get
- {
- return dogs;
- }
- set
- {
- dogs = value;
- }
- }
- public void AddDog(string name, int age)
- {
- Dog dog = new Dog(name, age);
- Dogs.Add(dog);
- }
- public double AverageAge()
- {
- double sum = 0;
- int count = 0;
- foreach (Dog dog in Dogs)
- {
- sum += dog.Age;
- count++;
- }
- return sum / count;
- }
- public List<string> FilterDogsByAge(int age)
- {
- List<string> dogs = new List<string>();
- foreach (Dog dog in Dogs)
- {
- if (dog.Age < age)
- {
- dogs.Add(dog.Name);
- }
- }
- return dogs;
- }
- public List<Dog> SortAscendingByName()
- {
- List<Dog> sorted = Dogs.OrderBy(dog => dog.Name).ToList();
- Dogs = sorted;
- return sorted;
- }
- public List<Dog> SortDescendingByAge()
- {
- List<Dog> sorted = Dogs.OrderByDescending(dog => dog.Age).ToList();
- Dogs = sorted;
- return sorted;
- }
- public bool CheckDogIsInHotel(string name)
- {
- foreach (Dog dog in Dogs)
- {
- if (dog.Name == name)
- {
- return true;
- }
- }
- return false;
- }
- public string[] ProvideInformationAboutAllDogs()
- {
- List<string> infoList = new List<string>();
- foreach (Dog dog in Dogs)
- {
- infoList.Add(dog.ToString());
- }
- return infoList.ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement