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
- All required new classes, enums, or interfaces 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 2 new source files.
- Update 4 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 3.4 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/Animals/Bird.csZooScenario/Business Classes/Animals/Mammal.cs
Files to update
ZooScenario/Business Classes/Animal.csZooScenario/Business Classes/Animals/Dingo.csZooScenario/Business Classes/Animals/Hummingbird.csZooScenario/Business Classes/Animals/Platypus.cs
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
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
- Save all files.
- Build the solution.
- Resolve compiler errors before continuing.
- Run the application.
- Exercise the new or updated behavior associated with Zoo 3.5.
- 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.