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

Task List

  1. Update 3 existing source files.
  2. Build the solution and resolve any compiler errors.
  3. 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

0
new instructional files
3
existing files changed
0
project-file updates

Files to create

Files to update

Create New Files

No new instructional source files are required for this checkpoint.

Update Existing Files

Temporary screenshot for Zoo 2.2: Update Existing Files
Temporary screenshot location: 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

Temporary screenshot for Zoo 2.2: Check Your Work
Temporary screenshot location: Check Your Work.
  1. Save all files.
  2. Build the solution.
  3. Resolve compiler errors before continuing.
  4. Run the application.
  5. Exercise the behavior associated with Zoo 2.2.
  6. 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.