Overview
Activity
Update the Zoo project to checkpoint 1.7.
User Story
As a developer, I want to complete the Zoo 1.7 checkpoint so the project includes the required programming concepts and behavior.
Acceptance Criteria
- All required new source files exist in the correct folders.
- 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
- Create 1 new source file.
- Update 5 existing source files.
- Confirm the new files are included in the project.
- 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 1.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
ZooScenario/Business Classes/Food.cs
Files to update
ZooScenario/Business Classes/Animal.csZooScenario/Business Classes/BirthingRoom.csZooScenario/Business Classes/Employee.csZooScenario/Business Classes/Zoo.csZooScenario/MainWindow.xaml.cs
Create New Files
ZooScenario/Business Classes/Food.cs
Create this file with the following checkpoint source:
using System;
using System.Collections.Generic;
using System.Text;
namespace ZooScenario
{
/// <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>
/// The weight of the food.
/// </summary>
public double Weight;
}
}
Update Existing Files
ZooScenario/Business Classes/Animal.cs
Apply the following code changes:
--- 1.6/ZooScenario/Business Classes/Animal.cs
+++ 1.7/ZooScenario/Business Classes/Animal.cs
@@ -56,17 +56,17 @@
/// <summary>
/// Eats a specific amount of food.
/// </summary>
- /// <param name="foodWeight">The weight of the food the animal eats.</param>
- public void Eat(double foodWeight)
+ /// <param name="food">The food the animal eats.</param>
+ public void Eat(Food food)
{
- if (foodWeight > 0)
+ if (food.Weight > 0)
{
- double weightGain = foodWeight * 0.8;
+ double weightGain = food.Weight * 0.8;
this.Weight += weightGain;
if (this.GetIsPregnant())
{
- double babyWeightGain = foodWeight * 0.1;
+ double babyWeightGain = food.Weight * 0.1;
this.Baby.Weight += babyWeightGain;
}
ZooScenario/Business Classes/BirthingRoom.cs
Apply the following code changes:
--- 1.6/ZooScenario/Business Classes/BirthingRoom.cs
+++ 1.7/ZooScenario/Business Classes/BirthingRoom.cs
@@ -48,11 +48,15 @@
/// <summary>
/// Helps the mother animal rest.
/// </summary>
+ /// <param name="mother">The mother animal.</param>
/// <param name="temperatureIncrease">The amount to increase the temperature.</param>
- public void WakeMotherUp(double temperatureIncrease)
+ public void WakeMotherUp(Animal mother, double temperatureIncrease)
{
- this.Mother.WakeUp();
- this.WarmRoom(temperatureIncrease);
+ if (mother != null)
+ {
+ mother.WakeUp();
+ this.WarmRoom(temperatureIncrease);
+ }
}
}
}
ZooScenario/Business Classes/Employee.cs
Apply the following code changes:
--- 1.6/ZooScenario/Business Classes/Employee.cs
+++ 1.7/ZooScenario/Business Classes/Employee.cs
@@ -31,6 +31,24 @@
public Animal AssignedAnimal;
/// <summary>
+ /// Assigns an animal to this employee.
+ /// </summary>
+ /// <param name="animal">The animal assigned to this employee.</param>
+ public void AssignAnimal(Animal animal)
+ {
+ this.AssignedAnimal = animal;
+ }
+
+ /// <summary>
+ /// Gets the animal assigned to this employee.
+ /// </summary>
+ /// <returns>The animal assigned to this employee.</returns>
+ public Animal GetAssignedAnimal()
+ {
+ return this.AssignedAnimal;
+ }
+
+ /// <summary>
/// Sells a specific number of tickets.
/// </summary>
/// <param name="ticketCount">The number of tickets sold.</param>
@@ -47,9 +65,14 @@
/// </summary>
public void FeedAnimal()
{
- if (this.AssignedAnimal != null)
+ Animal animal = this.GetAssignedAnimal();
+
+ Food food = new Food();
+ food.Weight = 1.0;
+
+ if (animal != null)
{
- this.AssignedAnimal.Eat(0.5);
+ animal.Eat(food);
}
}
}
ZooScenario/Business Classes/Zoo.cs
Apply the following code changes:
--- 1.6/ZooScenario/Business Classes/Zoo.cs
+++ 1.7/ZooScenario/Business Classes/Zoo.cs
@@ -93,7 +93,10 @@
{
decimal foodPayment = this.Visitor.RemoveMoney(foodCost);
foodWeight = this.AnimalSnackMachine.SellFood(foodPayment);
- this.FeaturedAnimal.Eat(foodWeight);
+ Food food = new Food();
+ food.Weight = foodWeight;
+
+ this.FeaturedAnimal.Eat(food);
}
return foodWeight;
@@ -105,7 +108,7 @@
/// <param name="temperatureIncrease">The amount to increase the temperature.</param>
public void PrepareBirthingRoom(double temperatureIncrease)
{
- this.BirthArea.WakeMotherUp(temperatureIncrease);
+ this.BirthArea.WakeMotherUp(this.BirthArea.Mother, temperatureIncrease);
}
/// <summary>
@@ -117,5 +120,23 @@
{
this.AnimalSnackMachine.FillVendingMachine(firstBagPounds, secondBagPounds);
}
+
+ /// <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;
+ }
}
}
ZooScenario/MainWindow.xaml.cs
Apply the following code changes:
--- 1.6/ZooScenario/MainWindow.xaml.cs
+++ 1.7/ZooScenario/MainWindow.xaml.cs
@@ -89,7 +89,7 @@
this.ComoZoo.BirthArea.Doctor.Name = "Flora";
this.ComoZoo.BirthArea.Doctor.Number = 98;
- this.ComoZoo.BirthArea.Doctor.AssignedAnimal = this.ComoZoo.FeaturedAnimal;
+ this.ComoZoo.BirthArea.Doctor.AssignAnimal(this.ComoZoo.GetFeaturedAnimal());
}
/// <summary>
@@ -149,7 +149,7 @@
// Assign field values of the doctor.
this.SanDiegoZoo.BirthArea.Doctor.Name = "Steve";
this.SanDiegoZoo.BirthArea.Doctor.Number = 24;
- this.SanDiegoZoo.BirthArea.Doctor.AssignedAnimal = this.SanDiegoZoo.FeaturedAnimal;
+ this.SanDiegoZoo.BirthArea.Doctor.AssignAnimal(this.SanDiegoZoo.GetFeaturedAnimal());
}
/// <summary>
@@ -182,10 +182,12 @@
/// <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 "
- + this.ComoZoo.FeaturedAnimal.Name + ". Featured animal weight: "
- + this.ComoZoo.FeaturedAnimal.Weight + ". Birthing room mother weight: "
+ + assignedAnimal.Name + ". Featured animal weight: "
+ + this.ComoZoo.GetFeaturedAnimal().Weight + ". Birthing room mother weight: "
+ this.ComoZoo.BirthArea.Mother.Weight + ".";
}
@@ -241,10 +243,12 @@
/// <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 "
- + this.SanDiegoZoo.FeaturedAnimal.Name + ". Featured animal weight: "
- + this.SanDiegoZoo.FeaturedAnimal.Weight + ". Birthing room mother weight: "
+ + assignedAnimal.Name + ". Featured animal weight: "
+ + this.SanDiegoZoo.GetFeaturedAnimal().Weight + ". Birthing room mother weight: "
+ this.SanDiegoZoo.BirthArea.Mother.Weight + ".";
}
ZooScenario/ZooScenario.csproj
Verify that Visual Studio added the required files to the project:
--- 1.6/ZooScenario/ZooScenario.csproj
+++ 1.7/ZooScenario/ZooScenario.csproj
@@ -71,6 +71,7 @@
<Compile Include="Business Classes\BirthingRoom.cs" />
<Compile Include="Business Classes\Booth.cs" />
<Compile Include="Business Classes\Employee.cs" />
+ <Compile Include="Business Classes\Food.cs" />
<Compile Include="Business Classes\Guest.cs" />
<Compile Include="Business Classes\Restroom.cs" />
<Compile Include="Business Classes\VendingMachine.cs" />
Check Your Work
- Save all files.
- Build the solution.
- Resolve compiler errors before continuing.
- Run the application.
- Exercise the behavior associated with Zoo 1.7.
- Compare your filenames, namespaces, signatures, and key values with the code shown above.
Summary
You completed Zoo 1.7 by creating the required files, modifying only files with meaningful source changes, and verifying the application.