Overview
Activity
Update the Zoo project to checkpoint 2.6.
User Story
As a developer, I want to complete the Zoo 2.6 checkpoint so the project includes the required programming concepts and behavior.
Acceptance Criteria
- Existing files contain the checkpoint changes shown in this walkthrough.
- The solution builds successfully.
- The application starts and the updated behavior can be exercised.
- Names, casing, namespaces, and member signatures match the checkpoint source.
Task List
- Update 13 existing source files.
- Build the solution and resolve any compiler errors.
- Run the application and verify the new behavior.
Exact Casing Matters
Use the filenames, class names, namespaces, method names, property names, and enum values exactly as shown.
Watch Out For
Do not copy build-output folders such as bin, obj, .vs, or package caches into your working project.
Before You Begin
Start with a clean copy of Zoo 2.5 End. Rename the extracted solution folder and solution file for the current checkpoint before making code changes.
Understand the Changes
new instructional files
existing files changed
project-file updates
Files to create
- None
Files to update
ZooScenario/Business Classes/Animal.csZooScenario/Business Classes/BirthingRoom.csZooScenario/Business Classes/Booth.csZooScenario/Business Classes/Employee.csZooScenario/Business Classes/Food.csZooScenario/Business Classes/Guest.csZooScenario/Business Classes/Pen.csZooScenario/Business Classes/Restroom.csZooScenario/Business Classes/Tank.csZooScenario/Business Classes/VendingMachine.csZooScenario/Business Classes/Wallet.csZooScenario/Business Classes/Zoo.csZooScenario/MainWindow.xaml.cs
Create New Files
No new instructional source files are required for this checkpoint.
Update Existing Files
ZooScenario/Business Classes/Animal.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/Animal.cs
+++ 2.6/ZooScenario/Business Classes/Animal.cs
@@ -44,6 +44,29 @@
/// The happiness level of the animal.
/// </summary>
private int happinessLevel;
+
+ /// <summary>
+ /// Initializes a new instance of the Animal class.
+ /// </summary>
+ /// <param name="name">The animal name.</param>
+ /// <param name="type">The animal type.</param>
+ /// <param name="gender">The animal gender.</param>
+ /// <param name="age">The animal age.</param>
+ /// <param name="weight">The animal weight.</param>
+ /// <param name="happinessLevel">The animal happiness level.</param>
+ public Animal(string name, string type, string gender, int age, double weight, int happinessLevel)
+ {
+ this.happinessLevel = happinessLevel;
+
+ if (age >= 0 && weight > 0)
+ {
+ this.Age = age;
+ this.Gender = gender;
+ this.Name = name;
+ this.Type = type;
+ this.Weight = weight;
+ }
+ }
/// <summary>
/// Makes the animal bark.
@@ -86,6 +109,15 @@
}
/// <summary>
+ /// Gets the happiness level of the animal.
+ /// </summary>
+ /// <returns>The happiness level of the animal.</returns>
+ public int GetHappinessLevel()
+ {
+ return this.happinessLevel;
+ }
+
+ /// <summary>
/// Gets whether the animal is pregnant.
/// </summary>
/// <returns>Whether the animal has a baby.</returns>
@@ -142,13 +174,7 @@
{
if (this.Gender == "Female" && !this.GetIsPregnant())
{
- this.Baby = new Animal();
- this.Baby.Age = 0;
- this.Baby.Gender = "Unknown";
- this.Baby.happinessLevel = 0;
- this.Baby.Name = "Baby " + this.Name;
- this.Baby.Type = this.Type;
- this.Baby.Weight = this.Weight * 0.1;
+ this.Baby = new Animal("Baby " + this.Name, this.Type, "Unknown", 0, this.Weight * 0.1, 0);
}
}
ZooScenario/Business Classes/BirthingRoom.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/BirthingRoom.cs
+++ 2.6/ZooScenario/Business Classes/BirthingRoom.cs
@@ -24,6 +24,16 @@
/// The doctor for the birthing room.
/// </summary>
public Employee Doctor;
+
+ /// <summary>
+ /// Initializes a new instance of the BirthingRoom class.
+ /// </summary>
+ /// <param name="doctor">The doctor for the birthing room.</param>
+ public BirthingRoom(Employee doctor)
+ {
+ this.Doctor = doctor;
+ this.Temperature = 77.0;
+ }
/// <summary>
/// Warms the birthing room.
ZooScenario/Business Classes/Booth.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/Booth.cs
+++ 2.6/ZooScenario/Business Classes/Booth.cs
@@ -26,6 +26,20 @@
public decimal TicketPrice;
/// <summary>
+ /// Initializes a new instance of the Booth class.
+ /// </summary>
+ /// <param name="attendant">The employee currently assigned to be the attendant of the booth.</param>
+ /// <param name="ticketPrice">The price of a ticket.</param>
+ public Booth(Employee attendant, decimal ticketPrice)
+ {
+ if (ticketPrice > 0)
+ {
+ this.Attendant = attendant;
+ this.TicketPrice = ticketPrice;
+ }
+ }
+
+ /// <summary>
/// Sells a ticket from the booth.
/// </summary>
/// <param name="ticketCount">The number of tickets to sell.</param>
ZooScenario/Business Classes/Employee.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/Employee.cs
+++ 2.6/ZooScenario/Business Classes/Employee.cs
@@ -29,6 +29,17 @@
/// The animal assigned to this employee.
/// </summary>
public Animal AssignedAnimal;
+
+ /// <summary>
+ /// Initializes a new instance of the Employee class.
+ /// </summary>
+ /// <param name="name">The employee name.</param>
+ /// <param name="number">The employee number.</param>
+ public Employee(string name, int number)
+ {
+ this.Name = name;
+ this.Number = number;
+ }
/// <summary>
/// Assigns an animal to this employee.
@@ -67,8 +78,7 @@
{
Animal animal = this.GetAssignedAnimal();
- Food food = new Food();
- food.SetWeight(1.0);
+ Food food = new Food(1.0);
if (animal != null)
{
ZooScenario/Business Classes/Food.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/Food.cs
+++ 2.6/ZooScenario/Business Classes/Food.cs
@@ -13,12 +13,21 @@
/// <summary>
/// The category of the food.
/// </summary>
- public string Category;
+ private string category;
/// <summary>
/// The weight of the food.
/// </summary>
private double weight;
+
+ /// <summary>
+ /// Initializes a new instance of the Food class.
+ /// </summary>
+ /// <param name="weight">The weight of the food.</param>
+ public Food(double weight)
+ {
+ this.SetWeight(weight);
+ }
/// <summary>
/// Gets the weight of the food.
@@ -40,5 +49,23 @@
this.weight = weight;
}
}
- }
+
+ /// <summary>
+ /// Gets the category of the food.
+ /// </summary>
+ /// <returns>The category of the food.</returns>
+ public string GetCategory()
+ {
+ return this.category;
+ }
+
+ /// <summary>
+ /// Sets the category of the food.
+ /// </summary>
+ /// <param name="category">The category of the food.</param>
+ public void SetCategory(string category)
+ {
+ this.category = category;
+ }
}
+}
ZooScenario/Business Classes/Guest.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/Guest.cs
+++ 2.6/ZooScenario/Business Classes/Guest.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Security.Permissions;
using System.Text;
namespace ZooScenario
@@ -13,17 +14,33 @@
/// <summary>
/// The age of the guest.
/// </summary>
- public int Age;
+ private int age;
/// <summary>
/// The name of the guest.
/// </summary>
- public string Name;
+ private string name;
/// <summary>
/// The guest's wallet.
/// </summary>
- public Wallet Wallet;
+ private Wallet wallet;
+
+ /// <summary>
+ /// Initializes a new instance of the Guest class.
+ /// </summary>
+ /// <param name="name">The guest name.</param>
+ /// <param name="age">The guest age.</param>
+ /// <param name="moneyBalance">The money balance.</param>
+ public Guest(string name, int age, decimal moneyBalance)
+ {
+ if (age >= 0)
+ {
+ this.age = age;
+ this.name = name;
+ this.wallet = new Wallet(moneyBalance);
+ }
+ }
/// <summary>
/// Buys a ticket.
@@ -32,7 +49,7 @@
/// <param name="ticketCount">The number of tickets to buy.</param>
public void BuyTicket(decimal ticketPrice, int ticketCount)
{
- this.Wallet.RemoveTicketPrice(ticketPrice, ticketCount);
+ this.wallet.RemoveTicketPrice(ticketPrice, ticketCount);
}
/// <summary>
@@ -41,7 +58,7 @@
/// <returns>The guest's current money balance.</returns>
public decimal GetMoneyBalance()
{
- return this.Wallet.GetMoneyBalance();
+ return this.wallet.GetMoneyBalance();
}
/// <summary>
@@ -51,8 +68,17 @@
/// <returns>The amount of money that was removed.</returns>
public decimal RemoveMoney(decimal amount)
{
- decimal amountRemoved = this.Wallet.RemoveMoney(amount);
+ decimal amountRemoved = this.wallet.RemoveMoney(amount);
return amountRemoved;
+ }
+
+ /// <summary>
+ /// Gets the name of the guest.
+ /// </summary>
+ /// <returns>Returns the string name of the guest.</returns>
+ public string GetName()
+ {
+ return this.name;
}
/// <summary>
ZooScenario/Business Classes/Pen.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/Pen.cs
+++ 2.6/ZooScenario/Business Classes/Pen.cs
@@ -14,6 +14,18 @@
/// The animal spaces in the pen.
/// </summary>
public Animal[] AnimalSpaces;
+
+ /// <summary>
+ /// Initializes a new instance of the Pen class.
+ /// </summary>
+ /// <param name="spaces">The number of animal spaces.</param>
+ public Pen(int spaces)
+ {
+ if (spaces > 0)
+ {
+ this.AnimalSpaces = new Animal[spaces];
+ }
+ }
/// <summary>
/// Adds an animal to the pen.
ZooScenario/Business Classes/Restroom.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/Restroom.cs
+++ 2.6/ZooScenario/Business Classes/Restroom.cs
@@ -19,5 +19,19 @@
/// The gender of the restroom.
/// </summary>
public string Gender;
+
+ /// <summary>
+ /// Initializes a new instance of the Restroom class.
+ /// </summary>
+ /// <param name="capacity">The maximum number of people allowed in the restroom at a given time.</param>
+ /// <param name="gender">The gender of the restroom.</param>
+ public Restroom(int capacity, string gender)
+ {
+ if (capacity > 0)
+ {
+ this.Capacity = capacity;
+ this.Gender = gender;
+ }
+ }
}
}
ZooScenario/Business Classes/Tank.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/Tank.cs
+++ 2.6/ZooScenario/Business Classes/Tank.cs
@@ -16,6 +16,19 @@
public Animal[,] AnimalSpaces;
/// <summary>
+ /// Initializes a new instance of the Tank class.
+ /// </summary>
+ /// <param name="rows">The number of rows.</param>
+ /// <param name="columns">The number of columns.</param>
+ public Tank(int rows, int columns)
+ {
+ if (rows > 0 && columns > 0)
+ {
+ this.AnimalSpaces = new Animal[rows, columns];
+ }
+ }
+
+ /// <summary>
/// Adds an animal to the tank.
/// </summary>
/// <param name="animal">The animal to add to the tank.</param>
ZooScenario/Business Classes/VendingMachine.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/VendingMachine.cs
+++ 2.6/ZooScenario/Business Classes/VendingMachine.cs
@@ -29,6 +29,19 @@
/// The amount of money currently in the vending machine.
/// </summary>
private decimal moneyBalance;
+
+ /// <summary>
+ /// Initializes a new instance of the VendingMachine class.
+ /// </summary>
+ /// <param name="foodPricePerPound">The food price per pound.</param>
+ /// <param name="foodStock">The food stock.</param>
+ /// <param name="moneyBalance">The money balance.</param>
+ public VendingMachine(decimal foodPricePerPound, double foodStock, decimal moneyBalance)
+ {
+ this.SetFoodPricePerPound(foodPricePerPound);
+ this.SetFoodStock(foodStock);
+ this.SetMoneyBalance(moneyBalance);
+ }
/// <summary>
/// Adds a bag of food to the vending machine.
ZooScenario/Business Classes/Wallet.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/Wallet.cs
+++ 2.6/ZooScenario/Business Classes/Wallet.cs
@@ -14,6 +14,15 @@
/// The amount of money currently contained within the wallet.
/// </summary>
private decimal moneyBalance;
+
+ /// <summary>
+ /// Initializes a new instance of the Wallet class.
+ /// </summary>
+ /// <param name="moneyBalance">The money balance.</param>
+ public Wallet(decimal moneyBalance)
+ {
+ this.SetMoneyBalance(moneyBalance);
+ }
/// <summary>
/// Adds money to the wallet.
ZooScenario/Business Classes/Zoo.cs
Apply the following code changes:
--- 2.5/ZooScenario/Business Classes/Zoo.cs
+++ 2.6/ZooScenario/Business Classes/Zoo.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Security.Permissions;
using System.Text;
namespace ZooScenario
@@ -13,62 +14,90 @@
/// <summary>
/// The zoo's animals.
/// </summary>
- public List<Animal> Animals;
+ private List<Animal> animals;
/// <summary>
/// The zoo's vending machine which allows guests to buy snacks for animals.
/// </summary>
- public VendingMachine AnimalSnackMachine;
+ private VendingMachine animalSnackMachine;
/// <summary>
/// The zoo's room for birthing animals.
/// </summary>
- public BirthingRoom BirthArea;
+ private BirthingRoom birthArea;
/// <summary>
/// The maximum number of guests the zoo can accommodate at a given time.
/// </summary>
- public int Capacity;
+ private int capacity;
/// <summary>
/// The zoo's featured animal.
/// </summary>
- public Animal FeaturedAnimal;
+ private Animal featuredAnimal;
/// <summary>
/// The zoo's dingo pen.
/// </summary>
- public Pen DingoPen;
+ private Pen dingoPen;
/// <summary>
/// The zoo's ladies' restroom.
/// </summary>
- public Restroom LadiesRoom;
+ private Restroom ladiesRoom;
/// <summary>
/// The zoo's men's restroom.
/// </summary>
- public Restroom MensRoom;
+ private Restroom mensRoom;
/// <summary>
/// The name of the zoo.
/// </summary>
- public string Name;
+ private string name;
/// <summary>
/// The zoo's platypus tank.
/// </summary>
- public Tank PlatypusTank;
+ private Tank platypusTank;
/// <summary>
/// The zoo's ticket booth.
/// </summary>
- public Booth TicketBooth;
+ private Booth ticketBooth;
/// <summary>
/// The zoo's current visitor.
/// </summary>
- public Guest Visitor;
+ private Guest visitor;
+
+ /// <summary>
+ /// Initializes a new instance of the Zoo class.
+ /// </summary>
+ /// <param name="name">The name of the zoo.</param>
+ /// <param name="capacity">The maximum number of guests the zoo can accommodate at a given time.</param>
+ /// <param name="restroomCapacity">The restroom capacity.</param>
+ /// <param name="foodPricePerPound">The price of food per pound.</param>
+ /// <param name="ticketPrice">The ticket price.</param>
+ /// <param name="doctor">The doctor for the birthing room.</param>
+ /// <param name="visitor">The zoo visitor.</param>
+ public Zoo(string name, int capacity, int restroomCapacity, decimal foodPricePerPound, decimal ticketPrice, Employee doctor, Guest visitor)
+ {
+ if (capacity > 0)
+ {
+ this.animals = new List<Animal>();
+ this.animalSnackMachine = new VendingMachine(foodPricePerPound, 0.0, 0.00m);
+ this.birthArea = new BirthingRoom(doctor);
+ this.capacity = capacity;
+ this.dingoPen = new Pen(5);
+ this.ladiesRoom = new Restroom(restroomCapacity, "Female");
+ this.mensRoom = new Restroom(restroomCapacity, "Male");
+ this.name = name;
+ this.platypusTank = new Tank(3, 3);
+ this.ticketBooth = new Booth(new Employee("Sam", 42), ticketPrice);
+ this.visitor = visitor;
+ }
+ }
/// <summary>
/// Opens the zoo for a visitor.
@@ -76,10 +105,10 @@
/// <param name="ticketCount">The number of tickets the visitor buys.</param>
public void OpenForVisitor(int ticketCount)
{
- if (this.FeaturedAnimal != null && this.Visitor != null && this.TicketBooth != null)
+ if (this.featuredAnimal != null && this.visitor != null && this.ticketBooth != null)
{
this.SellTicket(ticketCount);
- this.FeaturedAnimal.WakeUp();
+ this.featuredAnimal.WakeUp();
}
}
@@ -89,10 +118,10 @@
/// <param name="ticketCount">The number of tickets to sell.</param>
public void SellTicket(int ticketCount)
{
- if (ticketCount > 0 && this.Visitor != null && this.TicketBooth != null)
- {
- this.Visitor.BuyTicket(this.TicketBooth.TicketPrice, ticketCount);
- this.TicketBooth.SellTicket(ticketCount);
+ if (ticketCount > 0 && this.visitor != null && this.ticketBooth != null)
+ {
+ this.visitor.BuyTicket(this.ticketBooth.TicketPrice, ticketCount);
+ this.ticketBooth.SellTicket(ticketCount);
}
}
@@ -104,21 +133,20 @@
{
double foodWeight = 0.0;
- if (this.FeaturedAnimal != null && this.Visitor != null && this.AnimalSnackMachine != null)
- {
- double maxFoodWeight = this.FeaturedAnimal.GetPortionSize();
- decimal foodCost = this.AnimalSnackMachine.DetermineFoodCost(maxFoodWeight);
- decimal visitorMoneyBalance = this.Visitor.GetMoneyBalance();
-
- if (this.FeaturedAnimal.IsReadyToEat() && visitorMoneyBalance >= foodCost)
- {
- decimal foodPayment = this.Visitor.RemoveMoney(foodCost);
- foodWeight = this.AnimalSnackMachine.SellFood(foodPayment);
- Food food = new Food();
- food.Category = this.ChooseFoodCategory(this.FeaturedAnimal.Type);
- food.SetWeight(foodWeight);
-
- this.FeaturedAnimal.Eat(food);
+ if (this.featuredAnimal != null && this.visitor != null && this.animalSnackMachine != null)
+ {
+ double maxFoodWeight = this.featuredAnimal.GetPortionSize();
+ decimal foodCost = this.animalSnackMachine.DetermineFoodCost(maxFoodWeight);
+ decimal visitorMoneyBalance = this.visitor.GetMoneyBalance();
+
+ if (this.featuredAnimal.IsReadyToEat() && visitorMoneyBalance >= foodCost)
+ {
+ decimal foodPayment = this.visitor.RemoveMoney(foodCost);
+ foodWeight = this.animalSnackMachine.SellFood(foodPayment);
+ Food food = new Food(foodWeight);
+ food.SetCategory(this.ChooseFoodCategory(this.featuredAnimal.Type));
+
+ this.featuredAnimal.Eat(food);
}
}
@@ -131,9 +159,9 @@
/// <param name="temperatureIncrease">The amount to increase the temperature.</param>
public void PrepareBirthingRoom(double temperatureIncrease)
{
- if (this.BirthArea != null && this.BirthArea.Mother != null)
- {
- this.BirthArea.WakeMotherUp(this.BirthArea.Mother, temperatureIncrease);
+ if (this.birthArea != null && this.birthArea.Mother != null)
+ {
+ this.birthArea.WakeMotherUp(this.birthArea.Mother, temperatureIncrease);
}
}
@@ -144,7 +172,25 @@
/// <param name="secondBagPounds">The number of pounds in the second food bag.</param>
public void FillAnimalSnackMachine(double firstBagPounds, double secondBagPounds)
{
- this.AnimalSnackMachine.FillVendingMachine(firstBagPounds, secondBagPounds);
+ this.animalSnackMachine.FillVendingMachine(firstBagPounds, secondBagPounds);
+ }
+
+ /// <summary>
+ /// Gets the visitor of the zoo.
+ /// </summary>
+ /// <returns>The visitor of the zoo.</returns>
+ public Guest GetVisitor()
+ {
+ return this.visitor;
+ }
+
+ /// <summary>
+ /// Gets the zoo's birthing room.
+ /// </summary>
+ /// <returns>The zoo's birthing room.</returns>
+ public BirthingRoom GetBirthingRoom()
+ {
+ return this.birthArea;
}
/// <summary>
@@ -153,7 +199,7 @@
/// <returns>The zoo's featured animal.</returns>
public Animal GetFeaturedAnimal()
{
- return this.FeaturedAnimal;
+ return this.featuredAnimal;
}
/// <summary>
@@ -162,19 +208,28 @@
/// <param name="animal">The animal that becomes the featured animal.</param>
public void SetFeaturedAnimal(Animal animal)
{
- this.FeaturedAnimal = animal;
+ this.featuredAnimal = animal;
if (animal != null)
{
- if (animal.Type == "Dingo" && this.DingoPen != null)
- {
- this.DingoPen.AddAnimal(animal);
- }
- else if (animal.Type == "Platypus" && this.PlatypusTank != null)
- {
- this.PlatypusTank.AddAnimal(animal);
- }
- }
+ if (animal.Type == "Dingo" && this.dingoPen != null)
+ {
+ this.dingoPen.AddAnimal(animal);
+ }
+ else if (animal.Type == "Platypus" && this.platypusTank != null)
+ {
+ this.platypusTank.AddAnimal(animal);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets the zoo's vending machine.
+ /// </summary>
+ /// <returns>The zoo's vending machine.</returns>
+ public VendingMachine GetAnimalSnackMachine()
+ {
+ return this.animalSnackMachine;
}
/// <summary>
@@ -227,9 +282,9 @@
{
string display = string.Empty;
- if (this.DingoPen != null)
- {
- display = this.DingoPen.GetDisplayLocation();
+ if (this.dingoPen != null)
+ {
+ display = this.dingoPen.GetDisplayLocation();
}
return display;
@@ -243,9 +298,9 @@
{
string display = string.Empty;
- if (this.PlatypusTank != null)
- {
- display = this.PlatypusTank.GetDisplayLocation();
+ if (this.platypusTank != null)
+ {
+ display = this.platypusTank.GetDisplayLocation();
}
return display;
@@ -296,15 +351,15 @@
{
bool moved = false;
- if (this.FeaturedAnimal != null)
- {
- if (this.FeaturedAnimal.Type == "Dingo" && this.DingoPen != null)
- {
- moved = this.DingoPen.MoveAnimal(direction);
- }
- else if (this.FeaturedAnimal.Type == "Platypus" && this.PlatypusTank != null)
- {
- moved = this.PlatypusTank.MoveAnimal(direction);
+ if (this.featuredAnimal != null)
+ {
+ if (this.featuredAnimal.Type == "Dingo" && this.dingoPen != null)
+ {
+ moved = this.dingoPen.MoveAnimal(direction);
+ }
+ else if (this.featuredAnimal.Type == "Platypus" && this.platypusTank != null)
+ {
+ moved = this.platypusTank.MoveAnimal(direction);
}
}
@@ -317,11 +372,11 @@
/// <param name="animal">The animal to add to the zoo.</param>
public void AddAnimal(Animal animal)
{
- if (animal != null && this.Animals != null)
- {
- this.Animals.Add(animal);
-
- if (this.FeaturedAnimal == null)
+ if (animal != null && this.animals != null)
+ {
+ this.animals.Add(animal);
+
+ if (this.featuredAnimal == null)
{
this.SetFeaturedAnimal(animal);
}
@@ -336,15 +391,14 @@
{
int animalsFed = 0;
- if (this.Animals != null)
- {
- foreach (Animal animal in this.Animals)
+ if (this.animals != null)
+ {
+ foreach (Animal animal in this.animals)
{
if (animal != null && animal.IsReadyToEat())
{
- Food food = new Food();
- food.Category = this.ChooseFoodCategory(animal.Type);
- food.SetWeight(animal.GetPortionSize());
+ Food food = new Food(animal.GetPortionSize());
+ food.SetCategory(this.ChooseFoodCategory(animal.Type));
animal.Eat(food);
animalsFed = animalsFed + 1;
}
@@ -363,9 +417,9 @@
{
Animal foundAnimal = null;
- if (this.Animals != null)
- {
- foreach (Animal animal in this.Animals)
+ if (this.animals != null)
+ {
+ foreach (Animal animal in this.animals)
{
if (animal != null && animal.Name == name)
{
@@ -388,9 +442,9 @@
double totalWeight = 0.0;
int animalCount = this.GetAnimalCount();
- if (this.Animals != null)
- {
- foreach (Animal animal in this.Animals)
+ if (this.animals != null)
+ {
+ foreach (Animal animal in this.animals)
{
totalWeight = totalWeight + animal.Weight;
}
@@ -412,9 +466,9 @@
{
int animalCount = 0;
- if (this.Animals != null)
- {
- foreach (Animal animal in this.Animals)
+ if (this.animals != null)
+ {
+ foreach (Animal animal in this.animals)
{
if (animal != null)
{
@@ -434,9 +488,9 @@
{
int animalsWoken = 0;
- if (this.Animals != null)
- {
- foreach (Animal animal in this.Animals)
+ if (this.animals != null)
+ {
+ foreach (Animal animal in this.animals)
{
if (animal != null)
{
ZooScenario/MainWindow.xaml.cs
Apply the following code changes:
--- 2.5/ZooScenario/MainWindow.xaml.cs
+++ 2.6/ZooScenario/MainWindow.xaml.cs
@@ -46,15 +46,11 @@
/// <param name="age">The animal age.</param>
/// <param name="weight">The animal weight.</param>
/// <param name="isPregnant">Whether the animal is pregnant.</param>
+ /// <param name="happinessLevel">The animal's happiness level.</param>
/// <returns>The animal that was created.</returns>
- private Animal CreateAnimal(string name, string type, string gender, int age, double weight, bool isPregnant)
- {
- Animal animal = new Animal();
- animal.Age = age;
- animal.Gender = gender;
- animal.Name = name;
- animal.Type = type;
- animal.Weight = weight;
+ private Animal CreateAnimal(string name, string type, string gender, int age, double weight, bool isPregnant, int happinessLevel)
+ {
+ Animal animal = new Animal(name, type, gender, age, weight, happinessLevel);
if (isPregnant)
{
@@ -155,59 +151,20 @@
/// <param name="e">The event arguments for the event.</param>
private void newComoZooButton_Click(object sender, RoutedEventArgs e)
{
- this.ComoZoo = new Zoo();
- this.ComoZoo.Animals = new List<Animal>();
- this.ComoZoo.AnimalSnackMachine = new VendingMachine();
- this.ComoZoo.BirthArea = new BirthingRoom();
- this.ComoZoo.Capacity = 1000;
- this.ComoZoo.DingoPen = new Pen();
- this.ComoZoo.DingoPen.AnimalSpaces = new Animal[5];
- this.ComoZoo.FeaturedAnimal = new Animal();
- this.ComoZoo.LadiesRoom = new Restroom();
- this.ComoZoo.MensRoom = new Restroom();
- this.ComoZoo.Name = "Como Zoo";
- this.ComoZoo.TicketBooth = new Booth();
- this.ComoZoo.Visitor = new Guest();
- this.ComoZoo.Visitor.Wallet = new Wallet();
-
- this.ComoZoo.BirthArea.Mother = this.ComoZoo.FeaturedAnimal;
- this.ComoZoo.BirthArea.Temperature = 77.0;
- this.ComoZoo.BirthArea.Doctor = new Employee();
-
- this.ComoZoo.AnimalSnackMachine.SetFoodPricePerPound(0.75m);
- this.ComoZoo.AnimalSnackMachine.SetFoodStock(250.0);
- this.ComoZoo.AnimalSnackMachine.SetMoneyBalance(42.75m);
-
- this.ComoZoo.Visitor.Age = 12;
- this.ComoZoo.Visitor.Name = "Julia";
- this.ComoZoo.Visitor.Wallet.SetMoneyBalance(25.00m);
-
- this.ComoZoo.FeaturedAnimal.Age = 4;
- this.ComoZoo.FeaturedAnimal.Gender = "Female";
- this.ComoZoo.FeaturedAnimal.Name = "Dolly";
- this.ComoZoo.FeaturedAnimal.Type = "Dingo";
- this.ComoZoo.FeaturedAnimal.Weight = 35.3;
- this.ComoZoo.FeaturedAnimal.MakePregnant();
- this.ComoZoo.AddAnimal(this.ComoZoo.FeaturedAnimal);
- this.ComoZoo.AddAnimal(this.CreateAnimal("Dixie", "Dingo", "Female", 3, 33.8, true));
- this.ComoZoo.AddAnimal(this.CreateAnimal("Pammy", "Platypus", "Female", 2, 15.5, true));
- this.ComoZoo.AddAnimal(this.CreateAnimal("Helen", "Hummingbird", "Female", 2, 0.8, true));
-
- this.ComoZoo.LadiesRoom.Capacity = 4;
- this.ComoZoo.LadiesRoom.Gender = "Female";
-
- this.ComoZoo.MensRoom.Capacity = 4;
- this.ComoZoo.MensRoom.Gender = "Male";
-
- this.ComoZoo.TicketBooth.Attendant = new Employee();
- this.ComoZoo.TicketBooth.MoneyBalance = 0.00m;
- this.ComoZoo.TicketBooth.TicketPrice = 15.00m;
- this.ComoZoo.TicketBooth.Attendant.Name = "Sam";
- this.ComoZoo.TicketBooth.Attendant.Number = 42;
-
- this.ComoZoo.BirthArea.Doctor.Name = "Flora";
- this.ComoZoo.BirthArea.Doctor.Number = 98;
- this.ComoZoo.BirthArea.Doctor.AssignAnimal(this.ComoZoo.GetFeaturedAnimal());
+ Employee comoDoctor = new Employee("Flora", 98);
+ Guest comoVisitor = new Guest("Julia", 12, 25.00m);
+ this.ComoZoo = new Zoo("Como Zoo", 1000, 4, 0.75m, 15.00m, comoDoctor, comoVisitor);
+ this.ComoZoo.GetAnimalSnackMachine().SetFoodPricePerPound(0.75m);
+ this.ComoZoo.GetAnimalSnackMachine().SetMoneyBalance(42.75m);
+ Animal featuredAnimal = new Animal("Dolly", "Dingo", "Female", 4, 35.3, 2);
+ this.ComoZoo.SetFeaturedAnimal(featuredAnimal);
+ this.ComoZoo.GetFeaturedAnimal().MakePregnant();
+ this.ComoZoo.GetBirthingRoom().Mother = this.ComoZoo.GetFeaturedAnimal();
+ this.ComoZoo.GetBirthingRoom().Doctor.AssignAnimal(this.ComoZoo.GetFeaturedAnimal());
+ this.ComoZoo.AddAnimal(this.ComoZoo.GetFeaturedAnimal());
+ this.ComoZoo.AddAnimal(this.CreateAnimal("Dixie", "Dingo", "Female", 3, 33.8, true, 2));
+ this.ComoZoo.AddAnimal(this.CreateAnimal("Pammy", "Platypus", "Female", 2, 15.5, true, 3));
+ this.ComoZoo.AddAnimal(this.CreateAnimal("Helen", "Hummingbird", "Female", 2, 0.8, true, 1));
this.penDisplayTextBox.Text = this.ComoZoo.GetDingoPenDisplay();
}
@@ -218,63 +175,17 @@
/// <param name="e">The event arguments for the event.</param>
private void newSanDiegoZooButton_Click(object sender, RoutedEventArgs e)
{
- this.SanDiegoZoo = new Zoo();
- this.SanDiegoZoo.Animals = new List<Animal>();
- this.SanDiegoZoo.AnimalSnackMachine = new VendingMachine();
- this.SanDiegoZoo.BirthArea = new BirthingRoom();
- this.SanDiegoZoo.Capacity = 3000;
- this.SanDiegoZoo.PlatypusTank = new Tank();
- this.SanDiegoZoo.PlatypusTank.AnimalSpaces = new Animal[3, 3];
- this.SanDiegoZoo.FeaturedAnimal = new Animal();
- this.SanDiegoZoo.LadiesRoom = new Restroom();
- this.SanDiegoZoo.MensRoom = new Restroom();
- this.SanDiegoZoo.Name = "San Diego Zoo";
- this.SanDiegoZoo.TicketBooth = new Booth();
- this.SanDiegoZoo.Visitor = new Guest();
- this.SanDiegoZoo.Visitor.Wallet = new Wallet();
-
- // Assign field values of the birth area.
- this.SanDiegoZoo.BirthArea.Mother = this.SanDiegoZoo.FeaturedAnimal;
- this.SanDiegoZoo.BirthArea.Temperature = 77.0;
- this.SanDiegoZoo.BirthArea.Doctor = new Employee();
-
- // Assign field values of the animal snack machine.
- this.SanDiegoZoo.AnimalSnackMachine.SetFoodPricePerPound(1.20m);
- this.SanDiegoZoo.AnimalSnackMachine.SetFoodStock(3.5);
- this.SanDiegoZoo.AnimalSnackMachine.SetMoneyBalance(56.25m);
-
- // Assign field values of the visitor.
- this.SanDiegoZoo.Visitor.Age = 10;
- this.SanDiegoZoo.Visitor.Name = "Dakota";
- this.SanDiegoZoo.Visitor.Wallet.SetMoneyBalance(35.00m);
-
- // Assign field values of the featured animal.
- this.SanDiegoZoo.FeaturedAnimal.Age = 5;
- this.SanDiegoZoo.FeaturedAnimal.Gender = "Female";
- this.SanDiegoZoo.FeaturedAnimal.Name = "Patti";
- this.SanDiegoZoo.FeaturedAnimal.Type = "Platypus";
- this.SanDiegoZoo.FeaturedAnimal.Weight = 3.27;
- this.SanDiegoZoo.AddAnimal(this.SanDiegoZoo.FeaturedAnimal);
- this.SanDiegoZoo.AddAnimal(this.CreateAnimal("Harold", "Hummingbird", "Male", 1, 0.5, false));
- this.SanDiegoZoo.AddAnimal(this.CreateAnimal("Diego", "Dingo", "Male", 2, 37.4, false));
-
- // Assign field values of the restrooms.
- this.SanDiegoZoo.LadiesRoom.Capacity = 12;
- this.SanDiegoZoo.LadiesRoom.Gender = "Female";
- this.SanDiegoZoo.MensRoom.Capacity = 12;
- this.SanDiegoZoo.MensRoom.Gender = "Male";
-
- // Assign field values of the ticket booth.
- this.SanDiegoZoo.TicketBooth.Attendant = new Employee();
- this.SanDiegoZoo.TicketBooth.MoneyBalance = 0.00m;
- this.SanDiegoZoo.TicketBooth.TicketPrice = 25.50m;
- this.SanDiegoZoo.TicketBooth.Attendant.Name = "Sam";
- this.SanDiegoZoo.TicketBooth.Attendant.Number = 42;
-
- // Assign field values of the doctor.
- this.SanDiegoZoo.BirthArea.Doctor.Name = "Steve";
- this.SanDiegoZoo.BirthArea.Doctor.Number = 24;
- this.SanDiegoZoo.BirthArea.Doctor.AssignAnimal(this.SanDiegoZoo.GetFeaturedAnimal());
+ Employee sanDiegoDoctor = new Employee("Steve", 24);
+ Guest sanDiegoVisitor = new Guest("Dakota", 10, 35.00m);
+ this.SanDiegoZoo = new Zoo("San Diego Zoo", 3000, 12, 1.20m, 25.50m, sanDiegoDoctor, sanDiegoVisitor);
+ this.SanDiegoZoo.GetAnimalSnackMachine().SetFoodStock(3.5);
+ this.SanDiegoZoo.GetAnimalSnackMachine().SetMoneyBalance(56.25m);
+ this.SanDiegoZoo.SetFeaturedAnimal(new Animal("Patti", "Platypus", "Female", 5, 3.27, 3));
+ this.SanDiegoZoo.GetBirthingRoom().Mother = this.SanDiegoZoo.GetFeaturedAnimal();
+ this.SanDiegoZoo.GetBirthingRoom().Doctor.AssignAnimal(this.SanDiegoZoo.GetFeaturedAnimal());
+ this.SanDiegoZoo.AddAnimal(this.SanDiegoZoo.GetFeaturedAnimal());
+ this.SanDiegoZoo.AddAnimal(this.CreateAnimal("Harold", "Hummingbird", "Male", 1, 0.5, false, 5));
+ this.SanDiegoZoo.AddAnimal(this.CreateAnimal("Diego", "Dingo", "Male", 2, 37.4, false, 2));
this.tankDisplayTextBox.Text = this.SanDiegoZoo.GetPlatypusTankDisplay();
}
@@ -286,7 +197,7 @@
private void openComoZooButton_Click(object sender, RoutedEventArgs e)
{
this.ComoZoo.OpenForVisitor(1);
- this.informationTextBox.Text = "The Como Zoo is open for " + this.ComoZoo.Visitor.Name + ".";
+ this.informationTextBox.Text = "The Como Zoo is open for " + this.ComoZoo.GetVisitor().GetName() + ".";
}
/// <summary>
@@ -297,7 +208,7 @@
private void feedComoAnimalButton_Click(object sender, RoutedEventArgs e)
{
double foodWeight = this.ComoZoo.FeedFeaturedAnimal();
- this.informationTextBox.Text = this.ComoZoo.Visitor.Name + " fed " + this.ComoZoo.FeaturedAnimal.Name
+ this.informationTextBox.Text = this.ComoZoo.GetVisitor().GetName() + " fed " + this.ComoZoo.GetFeaturedAnimal().Name
+ " " + foodWeight + " pounds of food.";
}
@@ -308,13 +219,13 @@
/// <param name="e">The event arguments for the event.</param>
private void careForComoAnimalButton_Click(object sender, RoutedEventArgs e)
{
- Animal assignedAnimal = this.ComoZoo.BirthArea.Doctor.GetAssignedAnimal();
-
- this.ComoZoo.BirthArea.Doctor.FeedAnimal();
- this.informationTextBox.Text = this.ComoZoo.BirthArea.Doctor.Name + " cared for "
+ Animal assignedAnimal = this.ComoZoo.GetBirthingRoom().Doctor.GetAssignedAnimal();
+
+ this.ComoZoo.GetBirthingRoom().Doctor.FeedAnimal();
+ this.informationTextBox.Text = this.ComoZoo.GetBirthingRoom().Doctor.Name + " cared for "
+ assignedAnimal.Name + ". Featured animal weight: "
+ this.ComoZoo.GetFeaturedAnimal().Weight + ". Birthing room mother weight: "
- + this.ComoZoo.BirthArea.Mother.Weight + ".";
+ + this.ComoZoo.GetBirthingRoom().Mother.Weight + ".";
}
/// <summary>
@@ -413,7 +324,7 @@
private void openSanDiegoZooButton_Click(object sender, RoutedEventArgs e)
{
this.SanDiegoZoo.OpenForVisitor(2);
- this.informationTextBox.Text = "The San Diego Zoo is open for " + this.SanDiegoZoo.Visitor.Name + ".";
+ this.informationTextBox.Text = "The San Diego Zoo is open for " + this.SanDiegoZoo.GetVisitor().GetName() + ".";
}
/// <summary>
@@ -424,7 +335,7 @@
private void feedSanDiegoAnimalButton_Click(object sender, RoutedEventArgs e)
{
double foodWeight = this.SanDiegoZoo.FeedFeaturedAnimal();
- this.informationTextBox.Text = this.SanDiegoZoo.Visitor.Name + " fed " + this.SanDiegoZoo.FeaturedAnimal.Name
+ this.informationTextBox.Text = this.SanDiegoZoo.GetVisitor().GetName() + " fed " + this.SanDiegoZoo.GetFeaturedAnimal().Name
+ " " + foodWeight + " pounds of food.";
}
@@ -435,13 +346,13 @@
/// <param name="e">The event arguments for the event.</param>
private void careForSanDiegoAnimalButton_Click(object sender, RoutedEventArgs e)
{
- Animal assignedAnimal = this.SanDiegoZoo.BirthArea.Doctor.GetAssignedAnimal();
-
- this.SanDiegoZoo.BirthArea.Doctor.FeedAnimal();
- this.informationTextBox.Text = this.SanDiegoZoo.BirthArea.Doctor.Name + " cared for "
+ Animal assignedAnimal = this.SanDiegoZoo.GetBirthingRoom().Doctor.GetAssignedAnimal();
+
+ this.SanDiegoZoo.GetBirthingRoom().Doctor.FeedAnimal();
+ this.informationTextBox.Text = this.SanDiegoZoo.GetBirthingRoom().Doctor.Name + " cared for "
+ assignedAnimal.Name + ". Featured animal weight: "
+ this.SanDiegoZoo.GetFeaturedAnimal().Weight + ". Birthing room mother weight: "
- + this.SanDiegoZoo.BirthArea.Mother.Weight + ".";
+ + this.SanDiegoZoo.GetBirthingRoom().Mother.Weight + ".";
}
/// <summary>
Check Your Work
- Save all files.
- Build the solution.
- Resolve compiler errors before continuing.
- Run the application.
- Exercise the behavior associated with Zoo 2.6.
- Compare your filenames, namespaces, signatures, and key values with the code shown above.
Summary
You completed Zoo 2.6 by creating the required files, modifying only files with meaningful source changes, and verifying the application.