Overview
Activity
Update the Zoo project to checkpoint 2.2.
User Story
As a developer, I want to complete the Zoo 2.2 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 3 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.1 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/VendingMachine.csZooScenario/Business Classes/Zoo.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.1/ZooScenario/Business Classes/Animal.cs
+++ 2.2/ZooScenario/Business Classes/Animal.cs
@@ -123,6 +123,19 @@
}
/// <summary>
+ /// Grows the animal by a specific number of years.
+ /// </summary>
+ /// <param name="years">The number of years to grow.</param>
+ public void Grow(int years)
+ {
+ for (int year = 0; year < years; year++)
+ {
+ this.Age = this.Age + 1;
+ this.Weight = this.Weight + 1.0;
+ }
+ }
+
+ /// <summary>
/// Makes the animal pregnant.
/// </summary>
public void MakePregnant()
ZooScenario/Business Classes/VendingMachine.cs
Apply the following code changes:
--- 2.1/ZooScenario/Business Classes/VendingMachine.cs
+++ 2.2/ZooScenario/Business Classes/VendingMachine.cs
@@ -73,6 +73,18 @@
}
/// <summary>
+ /// Fills the vending machine until it reaches a target amount.
+ /// </summary>
+ /// <param name="targetStock">The target food stock.</param>
+ public void FillToTarget(double targetStock)
+ {
+ while (this.FoodStock < targetStock)
+ {
+ this.AddFoodBag(5.0);
+ }
+ }
+
+ /// <summary>
/// Gets the stock status of the vending machine.
/// </summary>
/// <returns>The stock status of the vending machine.</returns>
ZooScenario/Business Classes/Zoo.cs
Apply the following code changes:
--- 2.1/ZooScenario/Business Classes/Zoo.cs
+++ 2.2/ZooScenario/Business Classes/Zoo.cs
@@ -155,7 +155,7 @@
/// </summary>
/// <param name="animalType">The animal type.</param>
/// <returns>The food category.</returns>
- private string ChooseFoodCategory(string animalType)
+ public string ChooseFoodCategory(string animalType)
{
string foodCategory;
@@ -174,5 +174,22 @@
return foodCategory;
}
+
+ /// <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;
+ }
}
}
Check Your Work
- Save all files.
- Build the solution.
- Resolve compiler errors before continuing.
- Run the application.
- Exercise the behavior associated with Zoo 2.2.
- Compare your filenames, namespaces, signatures, and key values with the code shown above.
Summary
You completed Zoo 2.2 by creating the required files, modifying only files with meaningful source changes, and verifying the application.