Example #1
0
 /// <summary>
 /// The adopted animals.
 /// </summary>
 /// <param name="z">The current zoo.</param>
 /// <returns>The list of animals.</returns>
 public static IEnumerable <object> GetAdoptedAnimals(this Zoo z)
 {
     return(from g in z.Guests where g.AdoptedAnimal != null select new { g.Name, AnimalName = g.AdoptedAnimal.Name, Type = g.AdoptedAnimal.GetType().Name });
 }
Example #2
0
 /// <summary>
 /// The guests sorted by age.
 /// </summary>
 /// <param name="z">The current zoo.</param>
 /// <returns>The list of guests.</returns>
 public static IEnumerable <object> GetGuestsByAge(this Zoo z)
 {
     return(from g in z.Guests where g.Age >= 0 orderby g.Name ascending select new { g.Name, g.Age, g.Gender });
 }
Example #3
0
 /// <summary>
 /// The flying animals.
 /// </summary>
 /// <param name="z">The current zoo.</param>
 /// <returns>The list of animals.</returns>
 public static IEnumerable <object> GetFlyingAnimals(this Zoo z)
 {
     return(from a in z.Animals where a.MoveBehavior is FlyBehavior select new { Type = a.GetType().Name, a.Name });
 }
Example #4
0
 /// <summary>
 /// The female dingoes.
 /// </summary>
 /// <param name="z">The current zoo.</param>
 /// <returns>The list of animals.</returns>
 public static IEnumerable <object> GetFemaleDingoes(this Zoo z)
 {
     return(from a in z.Animals where a.GetType() == typeof(Dingo) && a.Gender == Gender.Female select new { a.Name, a.Age, a.Weight, a.Gender });
 }
Example #5
0
 /// <summary>
 /// The heavy animals.
 /// </summary>
 /// <param name="z">The current zoo.</param>
 /// <returns>The list of animals.</returns>
 public static IEnumerable <object> GetHeavyAnimals(this Zoo z)
 {
     return(from a in z.Animals where a.Weight >= 200 select new { Type = a.GetType().Name, a.Name, a.Age, a.Weight });
 }
Example #6
0
 /// <summary>
 /// Finds a guest based on name.
 /// </summary>
 /// <param name="z">The current zoo.</param>
 /// <param name="match">The matching item to find.</param>
 /// <returns>The first matching guest.</returns>
 public static Guest FindGuest(this Zoo z, Predicate <Guest> match)
 {
     return(z.Guests.ToList().Find(match));
 }
Example #7
0
 /// <summary>
 /// The youngest guests in the zoo.
 /// </summary>
 /// <param name="z">The current zoo.</param>
 /// <returns>The list of guests.</returns>
 public static IEnumerable <object> GetYoungGuests(this Zoo z)
 {
     return(from g in z.Guests where g.Age <= 10 select new { g.Name, g.Age });
 }
Example #8
0
 /// <summary>
 /// Finds the animal in the zoo.
 /// </summary>
 /// <param name="z">The current zoo.</param>
 /// <param name="match">The matching predicate.</param>
 /// <returns>Returns the found animal.</returns>
 public static Animal FindAnimal(this Zoo z, Predicate <Animal> match)
 {
     return(z.Animals.ToList().Find(match));
 }
Example #9
0
        /// <summary>
        /// Creates a new zoo.
        /// </summary>
        /// <returns> The created zoo.</returns>
        public static Zoo NewZoo()
        {
            Zoo zoo = new Zoo("Como Zoo", 1000, 4, 0.75m, 15.00m, 3640.25m, new Employee("Sam", 42), new Employee("Flora", 98), 3);

            // Add money to the animal snack machine.
            zoo.AnimalSnackMachine.AddMoney(42.75m);

            // Create the animals using the factory and add them all to the list of animals.

            Animal animal = AnimalFactory.CreateAnimal(AnimalType.Dingo, "Dolly", 4, 35.3, Gender.Female);

            animal.MakePregnant();

            zoo.AddAnimal(animal);

            animal = AnimalFactory.CreateAnimal(AnimalType.Dingo, "Dixie", 3, 33.8, Gender.Female);

            animal.MakePregnant();

            zoo.AddAnimal(animal);

            animal = AnimalFactory.CreateAnimal(AnimalType.Platypus, "Patty", 2, 15.5, Gender.Female);

            animal.MakePregnant();

            zoo.AddAnimal(animal);

            animal = AnimalFactory.CreateAnimal(AnimalType.Hummingbird, "Harold", 1, 0.5, Gender.Male);

            zoo.AddAnimal(animal);

            animal = AnimalFactory.CreateAnimal(AnimalType.Chimpanzee, "Noah", 12, 500, Gender.Male);

            zoo.AddAnimal(animal);

            animal = AnimalFactory.CreateAnimal(AnimalType.Eagle, "Tracy", 300, 10, Gender.Male);

            zoo.AddAnimal(animal);

            animal = AnimalFactory.CreateAnimal(AnimalType.Kangaroo, "Jeff", 25, 30, Gender.Male);

            zoo.AddAnimal(animal);

            animal = AnimalFactory.CreateAnimal(AnimalType.Ostrich, "Jake", 40, 200, Gender.Female);

            zoo.AddAnimal(animal);

            animal = AnimalFactory.CreateAnimal(AnimalType.Shark, "Max", 23, 185, Gender.Male);

            zoo.AddAnimal(animal);

            animal = AnimalFactory.CreateAnimal(AnimalType.Squirrel, "Matt", 21, 200, Gender.Male);

            zoo.AddAnimal(animal);

            Account account = new Account();

            account.AddMoney(50m);

            // Create a guest.
            Guest guest = new Guest("Greg", 44, 150.35m, WalletColor.Brown, Gender.Male, account);

            // Add the guest and sell the ticket to the guest.
            zoo.AddGuest(guest, zoo.SellTicket(guest));


            Wallet wallet = guest.Wallet;

            // Create a guest.
            guest = new Guest("Darla", 11, 25.25m, WalletColor.Salmon, Gender.Female, guest.Wallet);

            // Add the guest and sell the ticket to the guest.
            zoo.AddGuest(guest, zoo.SellTicket(guest));


            return(zoo);
        }
Example #10
0
 /// <summary>
 /// Finds a guest based on name.
 /// </summary>
 /// <param name="name">The name of the guest to find.</param>
 /// <returns>The first matching guest.</returns>
 public static Guest FindGuest(this Zoo zoo, Predicate <Guest> match) => zoo.Guests.ToList().Find(match);
Example #11
0
 /// <summary>
 /// Find an animal based on type.
 /// </summary>
 /// <param name="type">The type of the animal to find.</param>
 /// <returns>The first matching animal.</returns>
 public static Animal FindAnimal(this Zoo zoo, Predicate <Animal> match) => zoo.Animals.ToList().Find(match);
Example #12
0
        /// <summary>
        /// Creates a new zoo.
        /// </summary>
        /// <returns> The created zoo.</returns>
        public static Zoo NewZoo()
        {
            Zoo zoo = new Zoo("Como Zoo", 1000, 4, 0.75m, 15.00m, 3640.25m, new Employee("Sam", 42), new Employee("Flora", 98), 3);

            // Add money to the animal snack machine.
            zoo.AnimalSnackMachine.AddMoney(42.75m);

            // Define an animal variable.
            Animal animal;

            // Create a new Dingo and add him to the list of animals.
            animal = new Dingo("Dolly", 4, 35.3);

            animal.MakePregnant();

            zoo.AddAnimal(animal);

            // Create a new Dingo and add him to the list of animals.
            animal = new Dingo("Dixie", 3, 33.8);

            animal.MakePregnant();

            zoo.AddAnimal(animal);

            // Create a new platypus and add him to the list of animals.
            animal = new Platypus("Patty", 2, 15.5);

            animal.MakePregnant();

            zoo.AddAnimal(animal);

            // Create a new Hummingbird and add him to the list of animals.
            animal = new Hummingbird("Harold", 1, 0.5);

            zoo.AddAnimal(animal);

            // Create a new chimp and add him to the list of animals.
            animal = new Chimpanzee("Noah", 12, 500);

            zoo.AddAnimal(animal);

            // Create a new eagle and add him to the list of animals.
            animal = new Eagle("Tracy", 300, 10);

            zoo.AddAnimal(animal);

            // Create a new kangaroo and add him to the list of animals.
            animal = new Kangaroo("Jeff", 25, 30);

            zoo.AddAnimal(animal);

            // Create a new ostrich and add him to the list of animals.
            animal = new Ostrich("Jake", 40, 200);

            zoo.AddAnimal(animal);

            // Create a new shark and add him to the list of animals.
            animal = new Shark("Max", 23, 185);

            zoo.AddAnimal(animal);

            // Create a new squirrel and them to the list.
            animal = new Squirrel("Matt", 21, 200);

            zoo.AddAnimal(animal);

            // Create a guest.
            Guest guest = new Guest("Greg", 44, 150.35m, "Brown");

            // Add the guest and sell the ticket to the guest.
            zoo.AddGuest(guest, zoo.SellTicket(guest));

            // Create a guest.
            guest = new Guest("Darla", 11, 25.25m, "Salmon");

            // Add the guest and sell the ticket to the guest.
            zoo.AddGuest(guest, zoo.SellTicket(guest));

            return(zoo);
        }