Overview

Activity

Update the Zoo project from checkpoint 3.4 to checkpoint 3.5.

User Story

As a developer, I want to introduce intermediate Bird and Mammal classes and refine inheritance so the project demonstrates the programming concepts introduced in Zoo 3.5.

Acceptance Criteria

Task List

  1. Create 2 new source files.
  2. Update 4 existing source files.
  3. Confirm the new files are included in the project.
  4. Build the solution and resolve any compiler errors.
  5. 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 3.4 End. Rename the extracted solution folder and solution file for the current checkpoint before making code changes.

Understand the Changes

2
new instructional files
4
existing files changed
1
project-file updates

Files to create

Files to update

Create New Files

Temporary screenshot for Zoo 3.5: Create New Files
Temporary screenshot location: Create New Files.

ZooScenario/Business Classes/Animals/Bird.cs

Create this file with the following checkpoint source:

using System;
using System.Collections.Generic;
using System.Text;

namespace ZooScenario
{
    /// <summary>
    /// The bird class.
    /// </summary>
    public abstract class Bird : Animal
    {
        /// <summary>
        /// A new bird constructor.
        /// </summary>
        /// <param name="gender">The gender of the bird.</param>
        /// <param name="name">The name of the bird.</param>
        /// <param name="type">The type of the bird.</param>
        /// <param name="age">The age of the bird.</param>
        /// <param name="weight">The weight of the bird.</param>
        public Bird(Gender gender, string name, int age, double weight)
            : base(name, gender, age, weight)
        {
        }

        /// <summary>
        /// Gets the bird's eat weight gain percentage.
        /// </summary>
        protected override double EatWeightGainPercentage
        {
            get
            {
                return 0.64;
            }
        }

        /// <summary>
        /// Make the bird move.
        /// </summary>
        public override void Move()
        {
            this.Weight = this.Weight - (this.Weight * 0.06);
        }
    }
}

ZooScenario/Business Classes/Animals/Mammal.cs

Create this file with the following checkpoint source:

using System;
using System.Collections.Generic;
using System.Text;

namespace ZooScenario
{
    /// <summary>
    /// The mammal class.
    /// </summary>
    public abstract class Mammal : Animal
    {
        /// <summary>
        /// A new mammal constructor.
        /// </summary>
        /// <param name="gender">The gender of the mammal.</param>
        /// <param name="name">The name of the mammal.</param>
        /// <param name="type">The type of the mammal.</param>
        /// <param name="age">The age of the mammal.</param>
        /// <param name="weight">The weight of the mammal.</param>
        public Mammal(Gender gender, string name, int age, double weight)
            : base(name, gender, age, weight)
        {
        }

        /// <summary>
        /// Gets the mammals' eat weight gain percentage.
        /// </summary>
        protected override double EatWeightGainPercentage
        {
            get
            {
                return 0.8;
            }
        }
    }
}

Update Existing Files

Temporary screenshot for Zoo 3.5: Update Existing Files
Temporary screenshot location: Update Existing Files.

ZooScenario/Business Classes/Animal.cs

Apply the following code changes:

--- 3.4/ZooScenario/Business Classes/Animal.cs
+++ 3.5/ZooScenario/Business Classes/Animal.cs
@@ -7,7 +7,7 @@
     /// <summary>
     /// The class which is used to represent an animal.
     /// </summary>
-    public class Animal
+    public abstract class Animal
     {
         /// <summary>
         /// The age of the animal.
@@ -192,6 +192,17 @@
         }
 
         /// <summary>
+        /// Gets the percentage of food weight gained by eating.
+        /// </summary>
+        protected virtual double EatWeightGainPercentage
+        {
+            get
+            {
+                return 0.8;
+            }
+        }
+
+        /// <summary>
         /// Gets or sets the happinessLevel.
         /// </summary>
         protected int HappinessLevel
@@ -226,7 +237,7 @@
         {
             if (food != null && food.Weight > 0 && this.Weight > 0)
             {
-                double weightGain = food.Weight * 0.8;
+                double weightGain = food.Weight * this.EatWeightGainPercentage;
                 this.Weight += weightGain;
 
                 if (this.IsPregnant && this.Baby != null)

ZooScenario/Business Classes/Animals/Dingo.cs

Apply the following code changes:

--- 3.4/ZooScenario/Business Classes/Animals/Dingo.cs
+++ 3.5/ZooScenario/Business Classes/Animals/Dingo.cs
@@ -7,7 +7,7 @@
     /// <summary>
     /// A new Dingo class of type Animal.
     /// </summary>
-    public class Dingo : Animal
+    public class Dingo : Mammal
     {
         /// <summary>
         /// A new Dingo constructor.
@@ -17,7 +17,7 @@
         /// <param name="age">The age of the Dingo.</param>
         /// <param name="weight">The weight of the Dingo.</param>
         public Dingo(Gender gender, string name, int age, double weight)
-            : base(name, gender, age, weight)
+            : base(gender, name, age, weight)
         {
         }
 

ZooScenario/Business Classes/Animals/Hummingbird.cs

Apply the following code changes:

--- 3.4/ZooScenario/Business Classes/Animals/Hummingbird.cs
+++ 3.5/ZooScenario/Business Classes/Animals/Hummingbird.cs
@@ -7,7 +7,7 @@
     /// <summary>
     /// The hummingbird class.
     /// </summary>
-    public class Hummingbird : Animal
+    public class Hummingbird : Bird
     {
         /// <summary>
         /// A new hummingbird constructor.
@@ -17,7 +17,7 @@
         /// <param name="age">The age of the hummingbird.</param>
         /// <param name="weight">The weight of the hummingbird.</param>
         public Hummingbird(Gender gender, string name, int age, double weight)
-            : base(name, gender, age, weight)
+            : base(gender, name, age, weight)
         {
         }
 

ZooScenario/Business Classes/Animals/Platypus.cs

Apply the following code changes:

--- 3.4/ZooScenario/Business Classes/Animals/Platypus.cs
+++ 3.5/ZooScenario/Business Classes/Animals/Platypus.cs
@@ -7,7 +7,7 @@
     /// <summary>
     /// The platypus class.
     /// </summary>
-    public class Platypus : Animal
+    public class Platypus : Mammal
     {
         /// <summary>
         /// A new platypus constructor.
@@ -17,7 +17,7 @@
         /// <param name="age">The age of the platypus.</param>
         /// <param name="weight">The weight of the platypus.</param>
         public Platypus(Gender gender, string name, int age, double weight)
-            : base(name, gender, age, weight)
+            : base(gender, name, age, weight)
         {
         }
 

ZooScenario/ZooScenario.csproj

Verify that Visual Studio added the required files to the project:

--- 3.4/ZooScenario/ZooScenario.csproj
+++ 3.5/ZooScenario/ZooScenario.csproj
@@ -68,8 +68,10 @@
       <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Compile Include="Business Classes\Animal.cs" />
+    <Compile Include="Business Classes\Animals\Bird.cs" />
     <Compile Include="Business Classes\Animals\Dingo.cs" />
     <Compile Include="Business Classes\Animals\Hummingbird.cs" />
+    <Compile Include="Business Classes\Animals\Mammal.cs" />
     <Compile Include="Business Classes\Animals\Platypus.cs" />
     <Compile Include="Business Classes\BirthingRoom.cs" />
     <Compile Include="Business Classes\Booth.cs" />

Check Your Work

Temporary screenshot for Zoo 3.5: 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 new or updated behavior associated with Zoo 3.5.
  6. Compare your filenames, namespaces, signatures, and key values with the code shown above.

Summary

You updated the project from Zoo 3.4 End to Zoo 3.5 End by creating the required files, modifying only the files with meaningful source changes, and verifying the completed application.