Overview
Activity
Update the Zoo project to checkpoint 2.7.
User Story
As a developer, I want to complete the Zoo 2.7 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 14 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.6 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.xamlZooScenario/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.6/ZooScenario/Business Classes/Animal.cs
+++ 2.7/ZooScenario/Business Classes/Animal.cs
@@ -7,43 +7,42 @@
/// <summary>
/// The class which is used to represent an animal.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Animal
{
/// <summary>
/// The age of the animal.
/// </summary>
- public int Age;
+ private int age;
/// <summary>
/// The animal's baby.
/// </summary>
- public Animal Baby;
+ private Animal baby;
/// <summary>
/// The gender of the animal.
/// </summary>
- public string Gender;
+ private string gender;
+
+ /// <summary>
+ /// The happiness level of the animal.
+ /// </summary>
+ private int happinessLevel;
/// <summary>
/// The name of the animal.
/// </summary>
- public string Name;
+ private string name;
/// <summary>
/// The type of the animal.
/// </summary>
- public string Type;
+ private string type;
/// <summary>
/// The weight of the animal (in pounds).
/// </summary>
- public double Weight;
-
- /// <summary>
- /// The happiness level of the animal.
- /// </summary>
- private int happinessLevel;
+ private double weight;
/// <summary>
/// Initializes a new instance of the Animal class.
@@ -53,11 +52,8 @@
/// <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;
-
+ public Animal(string name, string type, string gender, int age, double weight)
+ {
if (age >= 0 && weight > 0)
{
this.Age = age;
@@ -69,11 +65,173 @@
}
/// <summary>
+ /// Gets or sets the age.
+ /// </summary>
+ public int Age
+ {
+ get
+ {
+ return this.age;
+ }
+
+ set
+ {
+ if (value >= 0)
+ {
+ this.age = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the baby.
+ /// </summary>
+ public Animal Baby
+ {
+ get
+ {
+ return this.baby;
+ }
+
+ set
+ {
+ this.baby = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the gender.
+ /// </summary>
+ public string Gender
+ {
+ get
+ {
+ return this.gender;
+ }
+
+ set
+ {
+ this.gender = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the name.
+ /// </summary>
+ public string Name
+ {
+ get
+ {
+ return this.name;
+ }
+
+ set
+ {
+ this.name = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the type.
+ /// </summary>
+ public string Type
+ {
+ get
+ {
+ return this.type;
+ }
+
+ set
+ {
+ this.type = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the weight.
+ /// </summary>
+ public double Weight
+ {
+ get
+ {
+ return this.weight;
+ }
+
+ set
+ {
+ if (value > 0)
+ {
+ this.weight = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the display name.
+ /// </summary>
+ public string DisplayName
+ {
+ get
+ {
+ return this.Name + " the " + this.Type;
+ }
+
+ set
+ {
+ if (value != null && value != string.Empty)
+ {
+ this.Name = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether the animal is pregnant.
+ /// </summary>
+ public bool IsPregnant
+ {
+ get
+ {
+ return this.Baby != null;
+ }
+ }
+
+ /// <summary>
+ /// Gets the maximum portion size the animal can eat.
+ /// </summary>
+ public double PortionSize
+ {
+ get
+ {
+ return this.Weight * 0.02;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the happinessLevel.
+ /// </summary>
+ protected int HappinessLevel
+ {
+ get
+ {
+ return this.happinessLevel;
+ }
+
+ set
+ {
+ if (value >= 0)
+ {
+ this.happinessLevel = value;
+ }
+ }
+ }
+
+ /// <summary>
/// Makes the animal bark.
/// </summary>
public void Bark()
{
- this.happinessLevel = this.happinessLevel + 1;
+ this.HappinessLevel = this.HappinessLevel + 1;
}
/// <summary>
@@ -82,14 +240,14 @@
/// <param name="food">The food the animal eats.</param>
public void Eat(Food food)
{
- if (food != null && food.GetWeight() > 0 && this.Weight > 0)
- {
- double weightGain = food.GetWeight() * 0.8;
+ if (food != null && food.Weight > 0 && this.Weight > 0)
+ {
+ double weightGain = food.Weight * 0.8;
this.Weight += weightGain;
- if (this.GetIsPregnant() && this.Baby != null)
- {
- double babyWeightGain = food.GetWeight() * 0.1;
+ if (this.IsPregnant && this.Baby != null)
+ {
+ double babyWeightGain = food.Weight * 0.1;
this.Baby.Weight += babyWeightGain;
}
@@ -109,33 +267,6 @@
}
/// <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>
- public bool GetIsPregnant()
- {
- return this.Baby != null;
- }
-
- /// <summary>
- /// Returns the maximum portion size the animal can eat.
- /// </summary>
- /// <returns>The maximum portion size for the animal.</returns>
- public double GetPortionSize()
- {
- return this.Weight * 0.02;
- }
-
- /// <summary>
/// Gets whether the animal is ready to eat.
/// </summary>
/// <returns>Whether the animal is ready to eat.</returns>
@@ -172,9 +303,10 @@
/// </summary>
public void MakePregnant()
{
- if (this.Gender == "Female" && !this.GetIsPregnant())
- {
- this.Baby = new Animal("Baby " + this.Name, this.Type, "Unknown", 0, this.Weight * 0.1, 0);
+ if (this.Gender == "Female" && !this.IsPregnant)
+ {
+ this.Baby = new Animal("Baby " + this.Name, this.Type, "Unknown", 0, this.Weight * 0.1);
+ this.Baby.HappinessLevel = 0;
}
}
@@ -183,7 +315,7 @@
/// </summary>
public void Move()
{
- this.happinessLevel = this.happinessLevel + 1;
+ this.HappinessLevel = this.HappinessLevel + 1;
}
/// <summary>
@@ -191,7 +323,7 @@
/// </summary>
public void StashInPouch()
{
- this.happinessLevel = this.happinessLevel + 1;
+ this.HappinessLevel = this.HappinessLevel + 1;
}
/// <summary>
ZooScenario/Business Classes/BirthingRoom.cs
Apply the following code changes:
--- 2.6/ZooScenario/Business Classes/BirthingRoom.cs
+++ 2.7/ZooScenario/Business Classes/BirthingRoom.cs
@@ -7,23 +7,22 @@
/// <summary>
/// The class which is used to represent a birthing room.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class BirthingRoom
{
/// <summary>
/// The current temperature of the birthing room.
/// </summary>
- public double Temperature;
+ private double temperature;
/// <summary>
/// The mother animal which is to give birth.
/// </summary>
- public Animal Mother;
+ private Animal mother;
/// <summary>
/// The doctor for the birthing room.
/// </summary>
- public Employee Doctor;
+ private Employee doctor;
/// <summary>
/// Initializes a new instance of the BirthingRoom class.
@@ -33,6 +32,54 @@
{
this.Doctor = doctor;
this.Temperature = 77.0;
+ }
+
+ /// <summary>
+ /// Gets or sets the temperature.
+ /// </summary>
+ public double Temperature
+ {
+ get
+ {
+ return this.temperature;
+ }
+
+ set
+ {
+ this.temperature = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the mother.
+ /// </summary>
+ public Animal Mother
+ {
+ get
+ {
+ return this.mother;
+ }
+
+ set
+ {
+ this.mother = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the doctor.
+ /// </summary>
+ public Employee Doctor
+ {
+ get
+ {
+ return this.doctor;
+ }
+
+ set
+ {
+ this.doctor = value;
+ }
}
/// <summary>
ZooScenario/Business Classes/Booth.cs
Apply the following code changes:
--- 2.6/ZooScenario/Business Classes/Booth.cs
+++ 2.7/ZooScenario/Business Classes/Booth.cs
@@ -7,23 +7,22 @@
/// <summary>
/// The class which is used to represent a booth.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Booth
{
/// <summary>
/// The employee currently assigned to be the attendant of the booth.
/// </summary>
- public Employee Attendant;
+ private Employee attendant;
/// <summary>
/// The amount of money in the booth.
/// </summary>
- public decimal MoneyBalance;
+ private decimal moneyBalance;
/// <summary>
/// The price of a ticket.
/// </summary>
- public decimal TicketPrice;
+ private decimal ticketPrice;
/// <summary>
/// Initializes a new instance of the Booth class.
@@ -36,6 +35,60 @@
{
this.Attendant = attendant;
this.TicketPrice = ticketPrice;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the attendant.
+ /// </summary>
+ public Employee Attendant
+ {
+ get
+ {
+ return this.attendant;
+ }
+
+ set
+ {
+ this.attendant = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the moneyBalance.
+ /// </summary>
+ public decimal MoneyBalance
+ {
+ get
+ {
+ return this.moneyBalance;
+ }
+
+ set
+ {
+ if (value >= 0)
+ {
+ this.moneyBalance = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the ticketPrice.
+ /// </summary>
+ public decimal TicketPrice
+ {
+ get
+ {
+ return this.ticketPrice;
+ }
+
+ set
+ {
+ if (value > 0)
+ {
+ this.ticketPrice = value;
+ }
}
}
ZooScenario/Business Classes/Employee.cs
Apply the following code changes:
--- 2.6/ZooScenario/Business Classes/Employee.cs
+++ 2.7/ZooScenario/Business Classes/Employee.cs
@@ -7,28 +7,27 @@
/// <summary>
/// The class which is used to represent an employee.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Employee
{
/// <summary>
/// The number of tickets the employee has sold.
/// </summary>
- public int TicketsSold;
+ private int ticketsSold;
/// <summary>
/// The name of the employee.
/// </summary>
- public string Name;
+ private string name;
/// <summary>
/// The employee's identification number.
/// </summary>
- public int Number;
+ private int number;
/// <summary>
/// The animal assigned to this employee.
/// </summary>
- public Animal AssignedAnimal;
+ private Animal assignedAnimal;
/// <summary>
/// Initializes a new instance of the Employee class.
@@ -39,6 +38,73 @@
{
this.Name = name;
this.Number = number;
+ }
+
+ /// <summary>
+ /// Gets or sets the ticketsSold.
+ /// </summary>
+ public int TicketsSold
+ {
+ get
+ {
+ return this.ticketsSold;
+ }
+
+ set
+ {
+ if (value >= 0)
+ {
+ this.ticketsSold = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the name.
+ /// </summary>
+ public string Name
+ {
+ get
+ {
+ return this.name;
+ }
+
+ set
+ {
+ this.name = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the number.
+ /// </summary>
+ public int Number
+ {
+ get
+ {
+ return this.number;
+ }
+
+ set
+ {
+ this.number = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the assignedAnimal.
+ /// </summary>
+ public Animal AssignedAnimal
+ {
+ get
+ {
+ return this.assignedAnimal;
+ }
+
+ set
+ {
+ this.assignedAnimal = value;
+ }
}
/// <summary>
@@ -76,7 +142,7 @@
/// </summary>
public void FeedAnimal()
{
- Animal animal = this.GetAssignedAnimal();
+ Animal animal = this.AssignedAnimal;
Food food = new Food(1.0);
ZooScenario/Business Classes/Food.cs
Apply the following code changes:
--- 2.6/ZooScenario/Business Classes/Food.cs
+++ 2.7/ZooScenario/Business Classes/Food.cs
@@ -7,7 +7,6 @@
/// <summary>
/// The class representing a food object.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Food
{
/// <summary>
@@ -26,7 +25,42 @@
/// <param name="weight">The weight of the food.</param>
public Food(double weight)
{
- this.SetWeight(weight);
+ this.Weight = weight;
+ }
+
+ /// <summary>
+ /// Gets or sets the category.
+ /// </summary>
+ public string Category
+ {
+ get
+ {
+ return this.category;
+ }
+
+ set
+ {
+ this.category = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the weight.
+ /// </summary>
+ public double Weight
+ {
+ get
+ {
+ return this.weight;
+ }
+
+ set
+ {
+ if (value > 0)
+ {
+ this.weight = value;
+ }
+ }
}
/// <summary>
@@ -35,7 +69,7 @@
/// <returns>The weight of the food.</returns>
public double GetWeight()
{
- return this.weight;
+ return this.Weight;
}
/// <summary>
@@ -46,26 +80,8 @@
{
if (weight > 0)
{
- this.weight = weight;
+ 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.6/ZooScenario/Business Classes/Guest.cs
+++ 2.7/ZooScenario/Business Classes/Guest.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Security.Permissions;
using System.Text;
namespace ZooScenario
@@ -8,7 +7,6 @@
/// <summary>
/// The class which is used to represent a guest.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Guest
{
/// <summary>
@@ -36,9 +34,76 @@
{
if (age >= 0)
{
- this.age = age;
- this.name = name;
- this.wallet = new Wallet(moneyBalance);
+ this.Age = age;
+ this.Name = name;
+ this.Wallet = new Wallet(moneyBalance);
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the age.
+ /// </summary>
+ public int Age
+ {
+ get
+ {
+ return this.age;
+ }
+
+ set
+ {
+ if (value >= 0)
+ {
+ this.age = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the name.
+ /// </summary>
+ public string Name
+ {
+ get
+ {
+ return this.name;
+ }
+
+ set
+ {
+ this.name = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the wallet.
+ /// </summary>
+ public Wallet Wallet
+ {
+ get
+ {
+ return this.wallet;
+ }
+
+ set
+ {
+ this.wallet = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the money balance of the guest's wallet.
+ /// </summary>
+ public decimal MoneyBalance
+ {
+ get
+ {
+ return this.Wallet.MoneyBalance;
+ }
+
+ set
+ {
+ this.Wallet.MoneyBalance = value;
}
}
@@ -49,7 +114,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>
@@ -58,7 +123,7 @@
/// <returns>The guest's current money balance.</returns>
public decimal GetMoneyBalance()
{
- return this.wallet.GetMoneyBalance();
+ return this.Wallet.MoneyBalance;
}
/// <summary>
@@ -68,17 +133,8 @@
/// <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.6/ZooScenario/Business Classes/Pen.cs
+++ 2.7/ZooScenario/Business Classes/Pen.cs
@@ -7,13 +7,12 @@
/// <summary>
/// The class which is used to represent a pen.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Pen
{
/// <summary>
/// The animal spaces in the pen.
/// </summary>
- public Animal[] AnimalSpaces;
+ private Animal[] animalSpaces;
/// <summary>
/// Initializes a new instance of the Pen class.
@@ -24,6 +23,22 @@
if (spaces > 0)
{
this.AnimalSpaces = new Animal[spaces];
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the animalSpaces.
+ /// </summary>
+ public Animal[] AnimalSpaces
+ {
+ get
+ {
+ return this.animalSpaces;
+ }
+
+ set
+ {
+ this.animalSpaces = value;
}
}
ZooScenario/Business Classes/Restroom.cs
Apply the following code changes:
--- 2.6/ZooScenario/Business Classes/Restroom.cs
+++ 2.7/ZooScenario/Business Classes/Restroom.cs
@@ -7,18 +7,17 @@
/// <summary>
/// The class which is used to represent a restroom.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Restroom
{
/// <summary>
+ /// The gender of the restroom.
+ /// </summary>
+ private string gender;
+
+ /// <summary>
/// The maximum number of people allowed in the restroom at a given time.
/// </summary>
- public int Capacity;
-
- /// <summary>
- /// The gender of the restroom.
- /// </summary>
- public string Gender;
+ private int capacity;
/// <summary>
/// Initializes a new instance of the Restroom class.
@@ -33,5 +32,40 @@
this.Gender = gender;
}
}
+
+ /// <summary>
+ /// Gets or sets the capacity.
+ /// </summary>
+ public int Capacity
+ {
+ get
+ {
+ return this.capacity;
+ }
+
+ set
+ {
+ if (value > 0)
+ {
+ this.capacity = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the gender.
+ /// </summary>
+ public string Gender
+ {
+ get
+ {
+ return this.gender;
+ }
+
+ set
+ {
+ this.gender = value;
+ }
+ }
}
}
ZooScenario/Business Classes/Tank.cs
Apply the following code changes:
--- 2.6/ZooScenario/Business Classes/Tank.cs
+++ 2.7/ZooScenario/Business Classes/Tank.cs
@@ -7,13 +7,12 @@
/// <summary>
/// The class which is used to represent a tank.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Tank
{
/// <summary>
/// The animal spaces in the tank.
/// </summary>
- public Animal[,] AnimalSpaces;
+ private Animal[,] animalSpaces;
/// <summary>
/// Initializes a new instance of the Tank class.
@@ -25,6 +24,22 @@
if (rows > 0 && columns > 0)
{
this.AnimalSpaces = new Animal[rows, columns];
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the animalSpaces.
+ /// </summary>
+ public Animal[,] AnimalSpaces
+ {
+ get
+ {
+ return this.animalSpaces;
+ }
+
+ set
+ {
+ this.animalSpaces = value;
}
}
ZooScenario/Business Classes/VendingMachine.cs
Apply the following code changes:
--- 2.6/ZooScenario/Business Classes/VendingMachine.cs
+++ 2.7/ZooScenario/Business Classes/VendingMachine.cs
@@ -7,7 +7,6 @@
/// <summary>
/// The class which is used to represent a vending machine.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class VendingMachine
{
/// <summary>
@@ -38,9 +37,66 @@
/// <param name="moneyBalance">The money balance.</param>
public VendingMachine(decimal foodPricePerPound, double foodStock, decimal moneyBalance)
{
- this.SetFoodPricePerPound(foodPricePerPound);
- this.SetFoodStock(foodStock);
- this.SetMoneyBalance(moneyBalance);
+ this.FoodPricePerPound = foodPricePerPound;
+ this.FoodStock = foodStock;
+ this.MoneyBalance = moneyBalance;
+ }
+
+ /// <summary>
+ /// Gets or sets the foodPricePerPound.
+ /// </summary>
+ public decimal FoodPricePerPound
+ {
+ get
+ {
+ return this.foodPricePerPound;
+ }
+
+ set
+ {
+ if (value > 0)
+ {
+ this.foodPricePerPound = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the foodStock.
+ /// </summary>
+ public double FoodStock
+ {
+ get
+ {
+ return this.foodStock;
+ }
+
+ set
+ {
+ if (value >= 0 && value <= this.foodCapacity)
+ {
+ this.foodStock = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the moneyBalance.
+ /// </summary>
+ public decimal MoneyBalance
+ {
+ get
+ {
+ return this.moneyBalance;
+ }
+
+ set
+ {
+ if (value >= 0)
+ {
+ this.moneyBalance = value;
+ }
+ }
}
/// <summary>
@@ -51,7 +107,7 @@
{
if (poundsOfFood > 0)
{
- this.foodStock = this.foodStock + poundsOfFood;
+ this.FoodStock = this.FoodStock + poundsOfFood;
}
}
@@ -74,7 +130,7 @@
{
if (moneyAmount > 0)
{
- this.moneyBalance += moneyAmount;
+ this.MoneyBalance += moneyAmount;
}
}
@@ -85,7 +141,7 @@
/// <returns>The cost of the food.</returns>
public decimal DetermineFoodCost(double maxFoodWeight)
{
- decimal maxFoodCost = (decimal)maxFoodWeight * this.foodPricePerPound;
+ decimal maxFoodCost = (decimal)maxFoodWeight * this.FoodPricePerPound;
decimal foodCost = Math.Round(maxFoodCost, 2);
return foodCost;
}
@@ -96,7 +152,7 @@
/// <param name="targetStock">The target food stock.</param>
public void FillToTarget(double targetStock)
{
- while (this.foodStock < targetStock)
+ while (this.FoodStock < targetStock)
{
this.AddFoodBag(5.0);
}
@@ -110,11 +166,11 @@
{
string stockLevel;
- if (this.foodStock <= 0)
+ if (this.FoodStock <= 0)
{
stockLevel = "Empty";
}
- else if (this.foodStock < 10)
+ else if (this.FoodStock < 10)
{
stockLevel = "Low";
}
@@ -145,7 +201,7 @@
/// <returns>The food stock.</returns>
public double GetFoodStock()
{
- return this.foodStock;
+ return this.FoodStock;
}
/// <summary>
@@ -156,7 +212,7 @@
{
if (foodPricePerPound > 0)
{
- this.foodPricePerPound = foodPricePerPound;
+ this.FoodPricePerPound = foodPricePerPound;
}
}
@@ -168,7 +224,7 @@
{
if (foodStock >= 0 && foodStock <= this.foodCapacity)
{
- this.foodStock = foodStock;
+ this.FoodStock = foodStock;
}
}
@@ -180,7 +236,7 @@
{
if (moneyBalance >= 0)
{
- this.moneyBalance = moneyBalance;
+ this.MoneyBalance = moneyBalance;
}
}
@@ -193,17 +249,17 @@
{
double foodWeight = 0.0;
- if (payment > 0 && this.foodPricePerPound > 0 && this.foodStock > 0)
+ if (payment > 0 && this.FoodPricePerPound > 0 && this.FoodStock > 0)
{
this.AddMoney(payment);
- foodWeight = (double)(payment / this.foodPricePerPound);
-
- if (foodWeight > this.foodStock)
- {
- foodWeight = this.foodStock;
- }
-
- this.foodStock -= foodWeight;
+ foodWeight = (double)(payment / this.FoodPricePerPound);
+
+ if (foodWeight > this.FoodStock)
+ {
+ foodWeight = this.FoodStock;
+ }
+
+ this.FoodStock -= foodWeight;
}
return foodWeight;
ZooScenario/Business Classes/Wallet.cs
Apply the following code changes:
--- 2.6/ZooScenario/Business Classes/Wallet.cs
+++ 2.7/ZooScenario/Business Classes/Wallet.cs
@@ -7,7 +7,6 @@
/// <summary>
/// The class which is used to represent a wallet.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Wallet
{
/// <summary>
@@ -21,7 +20,26 @@
/// <param name="moneyBalance">The money balance.</param>
public Wallet(decimal moneyBalance)
{
- this.SetMoneyBalance(moneyBalance);
+ this.MoneyBalance = moneyBalance;
+ }
+
+ /// <summary>
+ /// Gets or sets the moneyBalance.
+ /// </summary>
+ public decimal MoneyBalance
+ {
+ get
+ {
+ return this.moneyBalance;
+ }
+
+ set
+ {
+ if (value >= 0)
+ {
+ this.moneyBalance = value;
+ }
+ }
}
/// <summary>
@@ -32,7 +50,7 @@
{
if (moneyAmount > 0)
{
- this.moneyBalance = this.moneyBalance + moneyAmount;
+ this.MoneyBalance = this.MoneyBalance + moneyAmount;
}
}
@@ -42,7 +60,7 @@
/// <returns>The money balance.</returns>
public decimal GetMoneyBalance()
{
- return this.moneyBalance;
+ return this.MoneyBalance;
}
/// <summary>
@@ -54,7 +72,7 @@
{
decimal amountRemoved;
- if (amount > 0.00m && amount <= this.moneyBalance)
+ if (amount > 0.00m && amount <= this.MoneyBalance)
{
amountRemoved = amount;
}
@@ -63,7 +81,7 @@
amountRemoved = 0.00m;
}
- this.moneyBalance = this.moneyBalance - amountRemoved;
+ this.MoneyBalance = this.MoneyBalance - amountRemoved;
return amountRemoved;
}
@@ -92,7 +110,7 @@
{
if (moneyBalance >= 0)
{
- this.moneyBalance = moneyBalance;
+ this.MoneyBalance = moneyBalance;
}
}
}
ZooScenario/Business Classes/Zoo.cs
Apply the following code changes:
--- 2.6/ZooScenario/Business Classes/Zoo.cs
+++ 2.7/ZooScenario/Business Classes/Zoo.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Security.Permissions;
using System.Text;
namespace ZooScenario
@@ -8,7 +7,6 @@
/// <summary>
/// The class which is used to represent a zoo.
/// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Zoo
{
/// <summary>
@@ -85,17 +83,288 @@
{
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;
+ 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;
+ }
+
+ this.featuredAnimal = null;
+ }
+
+ /// <summary>
+ /// Gets or sets the animals.
+ /// </summary>
+ public List<Animal> Animals
+ {
+ get
+ {
+ return this.animals;
+ }
+
+ set
+ {
+ this.animals = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the animalSnackMachine.
+ /// </summary>
+ public VendingMachine AnimalSnackMachine
+ {
+ get
+ {
+ return this.animalSnackMachine;
+ }
+
+ set
+ {
+ this.animalSnackMachine = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the birthArea.
+ /// </summary>
+ public BirthingRoom BirthArea
+ {
+ get
+ {
+ return this.birthArea;
+ }
+
+ set
+ {
+ this.birthArea = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the capacity.
+ /// </summary>
+ public int Capacity
+ {
+ get
+ {
+ return this.capacity;
+ }
+
+ set
+ {
+ if (value > 0)
+ {
+ this.capacity = value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the featuredAnimal.
+ /// </summary>
+ public Animal FeaturedAnimal
+ {
+ get
+ {
+ return this.featuredAnimal;
+ }
+
+ set
+ {
+ this.featuredAnimal = value;
+
+ if (value != null)
+ {
+ if (value.Type == "Dingo" && this.DingoPen != null)
+ {
+ this.DingoPen.AddAnimal(value);
+ }
+ else if (value.Type == "Platypus" && this.PlatypusTank != null)
+ {
+ this.PlatypusTank.AddAnimal(value);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the dingoPen.
+ /// </summary>
+ public Pen DingoPen
+ {
+ get
+ {
+ return this.dingoPen;
+ }
+
+ set
+ {
+ this.dingoPen = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the ladiesRoom.
+ /// </summary>
+ public Restroom LadiesRoom
+ {
+ get
+ {
+ return this.ladiesRoom;
+ }
+
+ set
+ {
+ this.ladiesRoom = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the mensRoom.
+ /// </summary>
+ public Restroom MensRoom
+ {
+ get
+ {
+ return this.mensRoom;
+ }
+
+ set
+ {
+ this.mensRoom = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the name.
+ /// </summary>
+ public string Name
+ {
+ get
+ {
+ return this.name;
+ }
+
+ set
+ {
+ this.name = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the platypusTank.
+ /// </summary>
+ public Tank PlatypusTank
+ {
+ get
+ {
+ return this.platypusTank;
+ }
+
+ set
+ {
+ this.platypusTank = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the ticketBooth.
+ /// </summary>
+ public Booth TicketBooth
+ {
+ get
+ {
+ return this.ticketBooth;
+ }
+
+ set
+ {
+ this.ticketBooth = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the visitor.
+ /// </summary>
+ public Guest Visitor
+ {
+ get
+ {
+ return this.visitor;
+ }
+
+ set
+ {
+ this.visitor = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets the animal count.
+ /// </summary>
+ public int AnimalCount
+ {
+ get
+ {
+ return this.GetAnimalCount();
+ }
+ }
+
+ /// <summary>
+ /// Gets the average animal weight.
+ /// </summary>
+ public double AverageAnimalWeight
+ {
+ get
+ {
+ return this.GetAverageAnimalWeight();
+ }
+ }
+
+ /// <summary>
+ /// Gets the dingo pen display.
+ /// </summary>
+ public string DingoPenDisplay
+ {
+ get
+ {
+ return this.GetDingoPenDisplay();
+ }
+ }
+
+ /// <summary>
+ /// Gets the featured animal location.
+ /// </summary>
+ public string FeaturedAnimalLocation
+ {
+ get
+ {
+ string location = "No featured animal is assigned.";
+
+ if (this.FeaturedAnimal != null)
+ {
+ location = this.FeaturedAnimal.DisplayName + " is the featured animal.";
+ }
+
+ return location;
+ }
+ }
+
+ /// <summary>
+ /// Gets the platypus tank display.
+ /// </summary>
+ public string PlatypusTankDisplay
+ {
+ get
+ {
+ return this.GetPlatypusTankDisplay();
}
}
@@ -105,10 +374,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();
}
}
@@ -118,10 +387,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);
}
}
@@ -133,20 +402,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);
+ if (this.FeaturedAnimal != null && this.Visitor != null && this.AnimalSnackMachine != null)
+ {
+ double maxFoodWeight = this.FeaturedAnimal.PortionSize;
+ decimal foodCost = this.AnimalSnackMachine.DetermineFoodCost(maxFoodWeight);
+ decimal visitorMoneyBalance = this.Visitor.MoneyBalance;
+
+ 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);
+ food.Category = this.ChooseFoodCategory(this.FeaturedAnimal.Type);
+
+ this.FeaturedAnimal.Eat(food);
}
}
@@ -159,9 +428,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);
}
}
@@ -172,64 +441,229 @@
/// <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);
- }
-
- /// <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>
- /// Gets the zoo's featured animal.
- /// </summary>
- /// <returns>The zoo's featured animal.</returns>
- public Animal GetFeaturedAnimal()
- {
- return this.featuredAnimal;
- }
-
- /// <summary>
- /// Sets the zoo's featured animal.
- /// </summary>
- /// <param name="animal">The animal that becomes the featured animal.</param>
- public void SetFeaturedAnimal(Animal 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);
- }
- }
- }
-
- /// <summary>
- /// Gets the zoo's vending machine.
- /// </summary>
- /// <returns>The zoo's vending machine.</returns>
- public VendingMachine GetAnimalSnackMachine()
- {
- return this.animalSnackMachine;
+ this.AnimalSnackMachine.FillVendingMachine(firstBagPounds, secondBagPounds);
+ }
+
+ /// <summary>
+ /// Feeds the featured animal a specific number of times.
+ /// </summary>
+ /// <param name="feedCount">The number of times to feed the featured animal.</param>
+ /// <returns>The total weight of food given to the featured animal.</returns>
+ public double FeedFeaturedAnimalRepeatedly(int feedCount)
+ {
+ double totalFoodWeight = 0.0;
+
+ for (int count = 0; count < feedCount; count++)
+ {
+ totalFoodWeight = totalFoodWeight + this.FeedFeaturedAnimal();
+ }
+
+ return totalFoodWeight;
+ }
+
+ /// <summary>
+ /// Gets the dingo pen display.
+ /// </summary>
+ /// <returns>The dingo pen display.</returns>
+ public string GetDingoPenDisplay()
+ {
+ string display = string.Empty;
+
+ if (this.DingoPen != null)
+ {
+ display = this.DingoPen.GetDisplayLocation();
+ }
+
+ return display;
+ }
+
+ /// <summary>
+ /// Gets the platypus tank display.
+ /// </summary>
+ /// <returns>The platypus tank display.</returns>
+ public string GetPlatypusTankDisplay()
+ {
+ string display = string.Empty;
+
+ if (this.PlatypusTank != null)
+ {
+ display = this.PlatypusTank.GetDisplayLocation();
+ }
+
+ return display;
+ }
+
+ /// <summary>
+ /// Moves the featured animal down.
+ /// </summary>
+ /// <returns>True if the featured animal moved; otherwise, false.</returns>
+ public bool MoveFeaturedAnimalDown()
+ {
+ return this.MoveFeaturedAnimal("Down");
+ }
+
+ /// <summary>
+ /// Moves the featured animal left.
+ /// </summary>
+ /// <returns>True if the featured animal moved; otherwise, false.</returns>
+ public bool MoveFeaturedAnimalLeft()
+ {
+ return this.MoveFeaturedAnimal("Left");
+ }
+
+ /// <summary>
+ /// Moves the featured animal right.
+ /// </summary>
+ /// <returns>True if the featured animal moved; otherwise, false.</returns>
+ public bool MoveFeaturedAnimalRight()
+ {
+ return this.MoveFeaturedAnimal("Right");
+ }
+
+ /// <summary>
+ /// Moves the featured animal up.
+ /// </summary>
+ /// <returns>True if the featured animal moved; otherwise, false.</returns>
+ public bool MoveFeaturedAnimalUp()
+ {
+ return this.MoveFeaturedAnimal("Up");
+ }
+
+ /// <summary>
+ /// Adds an animal to the zoo.
+ /// </summary>
+ /// <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)
+ {
+ this.featuredAnimal = animal;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Feeds all animals.
+ /// </summary>
+ /// <returns>The number of animals that were fed.</returns>
+ public int FeedAllAnimals()
+ {
+ int animalsFed = 0;
+
+ if (this.Animals != null)
+ {
+ foreach (Animal animal in this.Animals)
+ {
+ if (animal != null && animal.IsReadyToEat())
+ {
+ Food food = new Food(animal.PortionSize);
+ food.Category = this.ChooseFoodCategory(animal.Type);
+ animal.Eat(food);
+ animalsFed = animalsFed + 1;
+ }
+ }
+ }
+
+ return animalsFed;
+ }
+
+ /// <summary>
+ /// Finds an animal by name.
+ /// </summary>
+ /// <param name="name">The name to find.</param>
+ /// <returns>The matching animal, or null if no matching animal is found.</returns>
+ public Animal FindAnimal(string name)
+ {
+ Animal foundAnimal = null;
+
+ if (this.Animals != null)
+ {
+ foreach (Animal animal in this.Animals)
+ {
+ if (animal != null && animal.Name == name)
+ {
+ foundAnimal = animal;
+ break;
+ }
+ }
+ }
+
+ return foundAnimal;
+ }
+
+ /// <summary>
+ /// Gets the average animal weight.
+ /// </summary>
+ /// <returns>The average animal weight.</returns>
+ public double GetAverageAnimalWeight()
+ {
+ double averageWeight = 0.0;
+ double totalWeight = 0.0;
+ int animalCount = this.GetAnimalCount();
+
+ if (this.Animals != null)
+ {
+ foreach (Animal animal in this.Animals)
+ {
+ totalWeight = totalWeight + animal.Weight;
+ }
+ }
+
+ if (animalCount > 0)
+ {
+ averageWeight = totalWeight / animalCount;
+ }
+
+ return averageWeight;
+ }
+
+ /// <summary>
+ /// Gets the animal count.
+ /// </summary>
+ /// <returns>The animal count.</returns>
+ public int GetAnimalCount()
+ {
+ int animalCount = 0;
+
+ if (this.Animals != null)
+ {
+ foreach (Animal animal in this.Animals)
+ {
+ if (animal != null)
+ {
+ animalCount = animalCount + 1;
+ }
+ }
+ }
+
+ return animalCount;
+ }
+
+ /// <summary>
+ /// Wakes all animals.
+ /// </summary>
+ /// <returns>The number of animals that were woken.</returns>
+ public int WakeAllAnimals()
+ {
+ int animalsWoken = 0;
+
+ if (this.Animals != null)
+ {
+ foreach (Animal animal in this.Animals)
+ {
+ if (animal != null)
+ {
+ animal.WakeUp();
+ animalsWoken = animalsWoken + 1;
+ }
+ }
+ }
+
+ return animalsWoken;
}
/// <summary>
@@ -237,7 +671,7 @@
/// </summary>
/// <param name="animalType">The animal type.</param>
/// <returns>The food category.</returns>
- public string ChooseFoodCategory(string animalType)
+ private string ChooseFoodCategory(string animalType)
{
string foodCategory;
@@ -258,249 +692,27 @@
}
/// <summary>
- /// Feeds the featured animal a specific number of times.
- /// </summary>
- /// <param name="feedCount">The number of times to feed the featured animal.</param>
- /// <returns>The total weight of food given to the featured animal.</returns>
- public double FeedFeaturedAnimalRepeatedly(int feedCount)
- {
- double totalFoodWeight = 0.0;
-
- for (int count = 0; count < feedCount; count++)
- {
- totalFoodWeight = totalFoodWeight + this.FeedFeaturedAnimal();
- }
-
- return totalFoodWeight;
- }
-
- /// <summary>
- /// Gets the dingo pen display.
- /// </summary>
- /// <returns>The dingo pen display.</returns>
- public string GetDingoPenDisplay()
- {
- string display = string.Empty;
-
- if (this.dingoPen != null)
- {
- display = this.dingoPen.GetDisplayLocation();
- }
-
- return display;
- }
-
- /// <summary>
- /// Gets the platypus tank display.
- /// </summary>
- /// <returns>The platypus tank display.</returns>
- public string GetPlatypusTankDisplay()
- {
- string display = string.Empty;
-
- if (this.platypusTank != null)
- {
- display = this.platypusTank.GetDisplayLocation();
- }
-
- return display;
- }
-
- /// <summary>
- /// Moves the featured animal down.
- /// </summary>
- /// <returns>True if the featured animal moved; otherwise, false.</returns>
- public bool MoveFeaturedAnimalDown()
- {
- return this.MoveFeaturedAnimal("Down");
- }
-
- /// <summary>
- /// Moves the featured animal left.
- /// </summary>
- /// <returns>True if the featured animal moved; otherwise, false.</returns>
- public bool MoveFeaturedAnimalLeft()
- {
- return this.MoveFeaturedAnimal("Left");
- }
-
- /// <summary>
- /// Moves the featured animal right.
- /// </summary>
- /// <returns>True if the featured animal moved; otherwise, false.</returns>
- public bool MoveFeaturedAnimalRight()
- {
- return this.MoveFeaturedAnimal("Right");
- }
-
- /// <summary>
- /// Moves the featured animal up.
- /// </summary>
- /// <returns>True if the featured animal moved; otherwise, false.</returns>
- public bool MoveFeaturedAnimalUp()
- {
- return this.MoveFeaturedAnimal("Up");
- }
-
- /// <summary>
/// Moves the featured animal.
/// </summary>
/// <param name="direction">The direction to move.</param>
/// <returns>True if the featured animal moved; otherwise, false.</returns>
- public bool MoveFeaturedAnimal(string direction)
+ private bool MoveFeaturedAnimal(string direction)
{
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);
}
}
return moved;
- }
-
- /// <summary>
- /// Adds an animal to the zoo.
- /// </summary>
- /// <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)
- {
- this.SetFeaturedAnimal(animal);
- }
- }
- }
-
- /// <summary>
- /// Feeds all animals.
- /// </summary>
- /// <returns>The number of animals that were fed.</returns>
- public int FeedAllAnimals()
- {
- int animalsFed = 0;
-
- if (this.animals != null)
- {
- foreach (Animal animal in this.animals)
- {
- if (animal != null && animal.IsReadyToEat())
- {
- Food food = new Food(animal.GetPortionSize());
- food.SetCategory(this.ChooseFoodCategory(animal.Type));
- animal.Eat(food);
- animalsFed = animalsFed + 1;
- }
- }
- }
-
- return animalsFed;
- }
-
- /// <summary>
- /// Finds an animal by name.
- /// </summary>
- /// <param name="name">The name to find.</param>
- /// <returns>The matching animal, or null if no matching animal is found.</returns>
- public Animal FindAnimal(string name)
- {
- Animal foundAnimal = null;
-
- if (this.animals != null)
- {
- foreach (Animal animal in this.animals)
- {
- if (animal != null && animal.Name == name)
- {
- foundAnimal = animal;
- break;
- }
- }
- }
-
- return foundAnimal;
- }
-
- /// <summary>
- /// Gets the average animal weight.
- /// </summary>
- /// <returns>The average animal weight.</returns>
- public double GetAverageAnimalWeight()
- {
- double averageWeight = 0.0;
- double totalWeight = 0.0;
- int animalCount = this.GetAnimalCount();
-
- if (this.animals != null)
- {
- foreach (Animal animal in this.animals)
- {
- totalWeight = totalWeight + animal.Weight;
- }
- }
-
- if (animalCount > 0)
- {
- averageWeight = totalWeight / animalCount;
- }
-
- return averageWeight;
- }
-
- /// <summary>
- /// Gets the animal count.
- /// </summary>
- /// <returns>The animal count.</returns>
- public int GetAnimalCount()
- {
- int animalCount = 0;
-
- if (this.animals != null)
- {
- foreach (Animal animal in this.animals)
- {
- if (animal != null)
- {
- animalCount = animalCount + 1;
- }
- }
- }
-
- return animalCount;
- }
-
- /// <summary>
- /// Wakes all animals.
- /// </summary>
- /// <returns>The number of animals that were woken.</returns>
- public int WakeAllAnimals()
- {
- int animalsWoken = 0;
-
- if (this.animals != null)
- {
- foreach (Animal animal in this.animals)
- {
- if (animal != null)
- {
- animal.WakeUp();
- animalsWoken = animalsWoken + 1;
- }
- }
- }
-
- return animalsWoken;
}
}
}
ZooScenario/MainWindow.xaml
Apply the following code changes:
--- 2.6/ZooScenario/MainWindow.xaml
+++ 2.7/ZooScenario/MainWindow.xaml
@@ -21,8 +21,8 @@
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Margin="5">
<!-- Start Como Zoo buttons -->
- <Button x:Name="newComoZooButton" Content="New Como Zoo" Click="newComoZooButton_Click"/>
- <Button x:Name="openComoZooButton" Content="Open Como Zoo" Click="openComoZooButton_Click"/>
+ <Button x:Name="newcomoZooButton" Content="New Como Zoo" Click="newcomoZooButton_Click"/>
+ <Button x:Name="opencomoZooButton" Content="Open Como Zoo" Click="opencomoZooButton_Click"/>
<Button x:Name="feedComoAnimalButton" Content="Darla, feed dingo" Click="feedComoAnimalButton_Click"/>
<Button x:Name="careForComoAnimalButton" Content="Flora, care for shared dingo" Click="careForComoAnimalButton_Click"/>
<Button x:Name="prepareComoBirthingRoomButton" Content="Prepare Como Birthing Room" Click="prepareComoBirthingRoomButton_Click"/>
@@ -51,8 +51,8 @@
</Separator>
<StackPanel Grid.Row="0" Grid.Column="2" Margin="5">
<!-- Start San Diego Zoo buttons -->
- <Button x:Name="newSanDiegoZooButton" Content="New San Diego Zoo" Click="newSanDiegoZooButton_Click"/>
- <Button x:Name="openSanDiegoZooButton" Content="Open San Diego Zoo" Click="openSanDiegoZooButton_Click"/>
+ <Button x:Name="newsanDiegoZooButton" Content="New San Diego Zoo" Click="newsanDiegoZooButton_Click"/>
+ <Button x:Name="opensanDiegoZooButton" Content="Open San Diego Zoo" Click="opensanDiegoZooButton_Click"/>
<Button x:Name="feedSanDiegoAnimalButton" Content="Dave, feed platypus" Click="feedSanDiegoAnimalButton_Click"/>
<Button x:Name="careForSanDiegoAnimalButton" Content="Steve, care for shared platypus" Click="careForSanDiegoAnimalButton_Click"/>
<Button x:Name="prepareSanDiegoBirthingRoomButton" Content="Prepare San Diego Birthing Room" Click="prepareSanDiegoBirthingRoomButton_Click"/>
ZooScenario/MainWindow.xaml.cs
Apply the following code changes:
--- 2.6/ZooScenario/MainWindow.xaml.cs
+++ 2.7/ZooScenario/MainWindow.xaml.cs
@@ -16,18 +16,17 @@
/// Contains interaction logic for MainWindow.xaml.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Event handlers may begin with lower-case letters.")]
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public partial class MainWindow : Window
{
/// <summary>
/// The Como Zoo.
/// </summary>
- public Zoo ComoZoo;
+ private Zoo comoZoo;
/// <summary>
/// The San Diego Zoo.
/// </summary>
- public Zoo SanDiegoZoo;
+ private Zoo sanDiegoZoo;
/// <summary>
/// Initializes a new instance of the MainWindow class.
@@ -46,11 +45,10 @@
/// <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, int happinessLevel)
- {
- Animal animal = new Animal(name, type, gender, age, weight, happinessLevel);
+ private Animal CreateAnimal(string name, string type, string gender, int age, double weight, bool isPregnant)
+ {
+ Animal animal = new Animal(name, type, gender, age, weight);
if (isPregnant)
{
@@ -67,7 +65,7 @@
/// <param name="e">The event arguments for the event.</param>
private void feedAllComoAnimalsButton_Click(object sender, RoutedEventArgs e)
{
- int animalsFed = this.ComoZoo.FeedAllAnimals();
+ int animalsFed = this.comoZoo.FeedAllAnimals();
this.informationTextBox.Text = "Fed " + animalsFed + " Como Zoo animals.";
}
@@ -78,7 +76,7 @@
/// <param name="e">The event arguments for the event.</param>
private void feedAllSanDiegoAnimalsButton_Click(object sender, RoutedEventArgs e)
{
- int animalsFed = this.SanDiegoZoo.FeedAllAnimals();
+ int animalsFed = this.sanDiegoZoo.FeedAllAnimals();
this.informationTextBox.Text = "Fed " + animalsFed + " San Diego Zoo animals.";
}
@@ -89,7 +87,7 @@
/// <param name="e">The event arguments for the event.</param>
private void getComoAnimalCountButton_Click(object sender, RoutedEventArgs e)
{
- this.informationTextBox.Text = "Como Zoo animal count: " + this.ComoZoo.GetAnimalCount() + ".";
+ this.informationTextBox.Text = "Como Zoo animal count: " + this.comoZoo.AnimalCount + ".";
}
/// <summary>
@@ -99,7 +97,7 @@
/// <param name="e">The event arguments for the event.</param>
private void getComoAverageWeightButton_Click(object sender, RoutedEventArgs e)
{
- this.informationTextBox.Text = "Como Zoo average animal weight: " + this.ComoZoo.GetAverageAnimalWeight() + ".";
+ this.informationTextBox.Text = "Como Zoo average animal weight: " + this.comoZoo.AverageAnimalWeight + ".";
}
/// <summary>
@@ -109,7 +107,7 @@
/// <param name="e">The event arguments for the event.</param>
private void getSanDiegoAnimalCountButton_Click(object sender, RoutedEventArgs e)
{
- this.informationTextBox.Text = "San Diego Zoo animal count: " + this.SanDiegoZoo.GetAnimalCount() + ".";
+ this.informationTextBox.Text = "San Diego Zoo animal count: " + this.sanDiegoZoo.AnimalCount + ".";
}
/// <summary>
@@ -119,7 +117,7 @@
/// <param name="e">The event arguments for the event.</param>
private void getSanDiegoAverageWeightButton_Click(object sender, RoutedEventArgs e)
{
- this.informationTextBox.Text = "San Diego Zoo average animal weight: " + this.SanDiegoZoo.GetAverageAnimalWeight() + ".";
+ this.informationTextBox.Text = "San Diego Zoo average animal weight: " + this.sanDiegoZoo.AverageAnimalWeight + ".";
}
/// <summary>
@@ -129,7 +127,7 @@
/// <param name="e">The event arguments for the event.</param>
private void wakeAllComoAnimalsButton_Click(object sender, RoutedEventArgs e)
{
- int animalsWoken = this.ComoZoo.WakeAllAnimals();
+ int animalsWoken = this.comoZoo.WakeAllAnimals();
this.informationTextBox.Text = "Woke " + animalsWoken + " Como Zoo animals.";
}
@@ -140,7 +138,7 @@
/// <param name="e">The event arguments for the event.</param>
private void wakeAllSanDiegoAnimalsButton_Click(object sender, RoutedEventArgs e)
{
- int animalsWoken = this.SanDiegoZoo.WakeAllAnimals();
+ int animalsWoken = this.sanDiegoZoo.WakeAllAnimals();
this.informationTextBox.Text = "Woke " + animalsWoken + " San Diego Zoo animals.";
}
@@ -149,23 +147,22 @@
/// </summary>
/// <param name="sender">The object that initiated the event.</param>
/// <param name="e">The event arguments for the event.</param>
- private void newComoZooButton_Click(object sender, RoutedEventArgs e)
+ private void newcomoZooButton_Click(object sender, RoutedEventArgs e)
{
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();
+ this.comoZoo = new Zoo("Como Zoo", 1000, 4, 0.75m, 15.00m, comoDoctor, comoVisitor);
+ this.comoZoo.AnimalSnackMachine.FoodStock = 250.0;
+ this.comoZoo.AnimalSnackMachine.MoneyBalance = 42.75m;
+ this.comoZoo.FeaturedAnimal = new Animal("Dolly", "Dingo", "Female", 4, 35.3);
+ this.comoZoo.FeaturedAnimal.MakePregnant();
+ this.comoZoo.BirthArea.Mother = this.comoZoo.FeaturedAnimal;
+ this.comoZoo.BirthArea.Doctor.AssignedAnimal = this.comoZoo.FeaturedAnimal;
+ 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.penDisplayTextBox.Text = this.comoZoo.DingoPenDisplay;
}
/// <summary>
@@ -173,20 +170,20 @@
/// </summary>
/// <param name="sender">The object that initiated the event.</param>
/// <param name="e">The event arguments for the event.</param>
- private void newSanDiegoZooButton_Click(object sender, RoutedEventArgs e)
+ private void newsanDiegoZooButton_Click(object sender, RoutedEventArgs e)
{
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();
+ this.sanDiegoZoo = new Zoo("San Diego Zoo", 3000, 12, 1.20m, 25.50m, sanDiegoDoctor, sanDiegoVisitor);
+ this.sanDiegoZoo.AnimalSnackMachine.FoodStock = 3.5;
+ this.sanDiegoZoo.AnimalSnackMachine.MoneyBalance = 56.25m;
+ this.sanDiegoZoo.FeaturedAnimal = new Animal("Patti", "Platypus", "Female", 5, 3.27);
+ this.sanDiegoZoo.BirthArea.Mother = this.sanDiegoZoo.FeaturedAnimal;
+ this.sanDiegoZoo.BirthArea.Doctor.AssignedAnimal = this.sanDiegoZoo.FeaturedAnimal;
+ 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));
+ this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
}
/// <summary>
@@ -194,10 +191,10 @@
/// </summary>
/// <param name="sender">The object that initiated the event.</param>
/// <param name="e">The event arguments for the event.</param>
- private void openComoZooButton_Click(object sender, RoutedEventArgs e)
- {
- this.ComoZoo.OpenForVisitor(1);
- this.informationTextBox.Text = "The Como Zoo is open for " + this.ComoZoo.GetVisitor().GetName() + ".";
+ 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 + ".";
}
/// <summary>
@@ -207,8 +204,8 @@
/// <param name="e">The event arguments for the event.</param>
private void feedComoAnimalButton_Click(object sender, RoutedEventArgs e)
{
- double foodWeight = this.ComoZoo.FeedFeaturedAnimal();
- this.informationTextBox.Text = this.ComoZoo.GetVisitor().GetName() + " fed " + this.ComoZoo.GetFeaturedAnimal().Name
+ double foodWeight = this.comoZoo.FeedFeaturedAnimal();
+ this.informationTextBox.Text = this.comoZoo.Visitor.Name + " fed " + this.comoZoo.FeaturedAnimal.Name
+ " " + foodWeight + " pounds of food.";
}
@@ -219,13 +216,13 @@
/// <param name="e">The event arguments for the event.</param>
private void careForComoAnimalButton_Click(object sender, RoutedEventArgs e)
{
- Animal assignedAnimal = this.ComoZoo.GetBirthingRoom().Doctor.GetAssignedAnimal();
-
- this.ComoZoo.GetBirthingRoom().Doctor.FeedAnimal();
- this.informationTextBox.Text = this.ComoZoo.GetBirthingRoom().Doctor.Name + " cared for "
+ Animal assignedAnimal = this.comoZoo.BirthArea.Doctor.AssignedAnimal;
+
+ this.comoZoo.BirthArea.Doctor.FeedAnimal();
+ this.informationTextBox.Text = this.comoZoo.BirthArea.Doctor.Name + " cared for "
+ assignedAnimal.Name + ". Featured animal weight: "
- + this.ComoZoo.GetFeaturedAnimal().Weight + ". Birthing room mother weight: "
- + this.ComoZoo.GetBirthingRoom().Mother.Weight + ".";
+ + this.comoZoo.FeaturedAnimal.Weight + ". Birthing room mother weight: "
+ + this.comoZoo.BirthArea.Mother.Weight + ".";
}
/// <summary>
@@ -235,7 +232,7 @@
/// <param name="e">The event arguments for the event.</param>
private void prepareComoBirthingRoomButton_Click(object sender, RoutedEventArgs e)
{
- this.ComoZoo.PrepareBirthingRoom(1.5);
+ this.comoZoo.PrepareBirthingRoom(1.5);
this.informationTextBox.Text = "The Como Zoo birthing room is ready.";
}
@@ -246,7 +243,7 @@
/// <param name="e">The event arguments for the event.</param>
private void fillComoVendingMachineButton_Click(object sender, RoutedEventArgs e)
{
- this.ComoZoo.FillAnimalSnackMachine(40.0, 35.0);
+ this.comoZoo.FillAnimalSnackMachine(40.0, 35.0);
this.informationTextBox.Text = "The Como Zoo animal snack machine has been filled.";
}
@@ -257,8 +254,8 @@
/// <param name="e">The event arguments for the event.</param>
private void moveDingoLeftButton_Click(object sender, RoutedEventArgs e)
{
- this.ComoZoo.MoveFeaturedAnimalLeft();
- this.penDisplayTextBox.Text = this.ComoZoo.GetDingoPenDisplay();
+ this.comoZoo.MoveFeaturedAnimalLeft();
+ this.penDisplayTextBox.Text = this.comoZoo.DingoPenDisplay;
}
/// <summary>
@@ -268,8 +265,8 @@
/// <param name="e">The event arguments for the event.</param>
private void moveDingoRightButton_Click(object sender, RoutedEventArgs e)
{
- this.ComoZoo.MoveFeaturedAnimalRight();
- this.penDisplayTextBox.Text = this.ComoZoo.GetDingoPenDisplay();
+ this.comoZoo.MoveFeaturedAnimalRight();
+ this.penDisplayTextBox.Text = this.comoZoo.DingoPenDisplay;
}
/// <summary>
@@ -279,8 +276,8 @@
/// <param name="e">The event arguments for the event.</param>
private void movePlatypusDownButton_Click(object sender, RoutedEventArgs e)
{
- this.SanDiegoZoo.MoveFeaturedAnimalDown();
- this.tankDisplayTextBox.Text = this.SanDiegoZoo.GetPlatypusTankDisplay();
+ this.sanDiegoZoo.MoveFeaturedAnimalDown();
+ this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
}
/// <summary>
@@ -290,8 +287,8 @@
/// <param name="e">The event arguments for the event.</param>
private void movePlatypusLeftButton_Click(object sender, RoutedEventArgs e)
{
- this.SanDiegoZoo.MoveFeaturedAnimalLeft();
- this.tankDisplayTextBox.Text = this.SanDiegoZoo.GetPlatypusTankDisplay();
+ this.sanDiegoZoo.MoveFeaturedAnimalLeft();
+ this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
}
/// <summary>
@@ -301,8 +298,8 @@
/// <param name="e">The event arguments for the event.</param>
private void movePlatypusRightButton_Click(object sender, RoutedEventArgs e)
{
- this.SanDiegoZoo.MoveFeaturedAnimalRight();
- this.tankDisplayTextBox.Text = this.SanDiegoZoo.GetPlatypusTankDisplay();
+ this.sanDiegoZoo.MoveFeaturedAnimalRight();
+ this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
}
/// <summary>
@@ -312,8 +309,8 @@
/// <param name="e">The event arguments for the event.</param>
private void movePlatypusUpButton_Click(object sender, RoutedEventArgs e)
{
- this.SanDiegoZoo.MoveFeaturedAnimalUp();
- this.tankDisplayTextBox.Text = this.SanDiegoZoo.GetPlatypusTankDisplay();
+ this.sanDiegoZoo.MoveFeaturedAnimalUp();
+ this.tankDisplayTextBox.Text = this.sanDiegoZoo.PlatypusTankDisplay;
}
/// <summary>
@@ -321,10 +318,10 @@
/// </summary>
/// <param name="sender">The object that initiated the event.</param>
/// <param name="e">The event arguments for the event.</param>
- private void openSanDiegoZooButton_Click(object sender, RoutedEventArgs e)
- {
- this.SanDiegoZoo.OpenForVisitor(2);
- this.informationTextBox.Text = "The San Diego Zoo is open for " + this.SanDiegoZoo.GetVisitor().GetName() + ".";
+ 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 + ".";
}
/// <summary>
@@ -334,8 +331,8 @@
/// <param name="e">The event arguments for the event.</param>
private void feedSanDiegoAnimalButton_Click(object sender, RoutedEventArgs e)
{
- double foodWeight = this.SanDiegoZoo.FeedFeaturedAnimal();
- this.informationTextBox.Text = this.SanDiegoZoo.GetVisitor().GetName() + " fed " + this.SanDiegoZoo.GetFeaturedAnimal().Name
+ double foodWeight = this.sanDiegoZoo.FeedFeaturedAnimal();
+ this.informationTextBox.Text = this.sanDiegoZoo.Visitor.Name + " fed " + this.sanDiegoZoo.FeaturedAnimal.Name
+ " " + foodWeight + " pounds of food.";
}
@@ -346,13 +343,13 @@
/// <param name="e">The event arguments for the event.</param>
private void careForSanDiegoAnimalButton_Click(object sender, RoutedEventArgs e)
{
- Animal assignedAnimal = this.SanDiegoZoo.GetBirthingRoom().Doctor.GetAssignedAnimal();
-
- this.SanDiegoZoo.GetBirthingRoom().Doctor.FeedAnimal();
- this.informationTextBox.Text = this.SanDiegoZoo.GetBirthingRoom().Doctor.Name + " cared for "
+ Animal assignedAnimal = this.sanDiegoZoo.BirthArea.Doctor.AssignedAnimal;
+
+ this.sanDiegoZoo.BirthArea.Doctor.FeedAnimal();
+ this.informationTextBox.Text = this.sanDiegoZoo.BirthArea.Doctor.Name + " cared for "
+ assignedAnimal.Name + ". Featured animal weight: "
- + this.SanDiegoZoo.GetFeaturedAnimal().Weight + ". Birthing room mother weight: "
- + this.SanDiegoZoo.GetBirthingRoom().Mother.Weight + ".";
+ + this.sanDiegoZoo.FeaturedAnimal.Weight + ". Birthing room mother weight: "
+ + this.sanDiegoZoo.BirthArea.Mother.Weight + ".";
}
/// <summary>
@@ -362,7 +359,7 @@
/// <param name="e">The event arguments for the event.</param>
private void prepareSanDiegoBirthingRoomButton_Click(object sender, RoutedEventArgs e)
{
- this.SanDiegoZoo.PrepareBirthingRoom(0.75);
+ this.sanDiegoZoo.PrepareBirthingRoom(0.75);
this.informationTextBox.Text = "The San Diego Zoo birthing room is ready.";
}
@@ -373,7 +370,7 @@
/// <param name="e">The event arguments for the event.</param>
private void fillSanDiegoVendingMachineButton_Click(object sender, RoutedEventArgs e)
{
- this.SanDiegoZoo.FillAnimalSnackMachine(25.0, 25.0);
+ this.sanDiegoZoo.FillAnimalSnackMachine(25.0, 25.0);
this.informationTextBox.Text = "The San Diego Zoo animal snack machine has been filled.";
}
}
Check Your Work
- Save all files.
- Build the solution.
- Resolve compiler errors before continuing.
- Run the application.
- Exercise the behavior associated with Zoo 2.7.
- Compare your filenames, namespaces, signatures, and key values with the code shown above.
Summary
You completed Zoo 2.7 by creating the required files, modifying only files with meaningful source changes, and verifying the application.