Overview
Activity
Update the Zoo project from checkpoint 3.5 to checkpoint 3.6.
User Story
As a developer, I want to introduce behavior interfaces and implement them in the appropriate animal classes so the project demonstrates the programming concepts introduced in Zoo 3.6.
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 4 new source files.
- Update 3 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.5 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/Interfaces/IEater.csZooScenario/Interfaces/IHatchable.csZooScenario/Interfaces/IMover.csZooScenario/Interfaces/IReproducer.cs
Files to update
ZooScenario/Business Classes/Animal.csZooScenario/Business Classes/Animals/Bird.csZooScenario/Business Classes/Animals/Platypus.cs
Create New Files
ZooScenario/Interfaces/IEater.cs
Create this file with the following checkpoint source:
using System;
using System.Collections.Generic;
using System.Text;
namespace ZooScenario
{
/// <summary>
/// The Eater interface class.
/// </summary>
public interface IEater
{
/// <summary>
/// Gets the portion size of what is being eaten.
/// </summary>
double PortionSize { get; }
/// <summary>
/// Gets the weight of the eater.
/// </summary>
double Weight { get; }
/// <summary>
/// Eats the food.
/// </summary>
/// <param name="food">The food being eaten.</param>
void Eat(Food food);
}
}
ZooScenario/Interfaces/IHatchable.cs
Create this file with the following checkpoint source:
using System;
using System.Collections.Generic;
using System.Text;
namespace ZooScenario
{
/// <summary>
/// The interface for objects that are hatchable.
/// </summary>
public interface IHatchable
{
/// <summary>
/// Hatches a new object.
/// </summary>
void Hatch();
}
}
ZooScenario/Interfaces/IMover.cs
Create this file with the following checkpoint source:
using System;
using System.Collections.Generic;
using System.Text;
namespace ZooScenario
{
/// <summary>
/// A new Mover interface class.
/// </summary>
public interface IMover
{
/// <summary>
/// Makes the object move.
/// </summary>
void Move();
}
}
ZooScenario/Interfaces/IReproducer.cs
Create this file with the following checkpoint source:
using System;
using System.Collections.Generic;
using System.Text;
namespace ZooScenario
{
/// <summary>
/// The interface for a reproducer.
/// </summary>
public interface IReproducer
{
/// <summary>
/// Gets a value indicating whether the individual is pregnant or not.
/// </summary>
bool IsPregnant { get; }
/// <summary>
/// Gets a value indicating the weight of the reproducer.
/// </summary>
double Weight { get; }
/// <summary>
/// Makes the individual pregnant.
/// </summary>
void MakePregnant();
/// <summary>
/// Makes the IReproducer reproduce.
/// </summary>
/// <returns>Returns the child IReproducer.</returns>
IReproducer Reproduce();
}
}
Update Existing Files
ZooScenario/Business Classes/Animal.cs
Apply the following code changes:
--- 3.5/ZooScenario/Business Classes/Animal.cs
+++ 3.6/ZooScenario/Business Classes/Animal.cs
@@ -7,7 +7,7 @@
/// <summary>
/// The class which is used to represent an animal.
/// </summary>
- public abstract class Animal
+ public abstract class Animal : IEater, IMover, IReproducer
{
/// <summary>
/// The age of the animal.
@@ -326,6 +326,23 @@
}
/// <summary>
+ /// Makes the animal reproduce.
+ /// </summary>
+ /// <returns>The baby animal.</returns>
+ public virtual IReproducer Reproduce()
+ {
+ IReproducer baby = this.Baby;
+
+ if (baby == null)
+ {
+ this.MakePregnant();
+ baby = this.Baby;
+ }
+
+ return baby;
+ }
+
+ /// <summary>
/// Stores food in a pouch.
/// </summary>
public void StashInPouch()
ZooScenario/Business Classes/Animals/Bird.cs
Apply the following code changes:
--- 3.5/ZooScenario/Business Classes/Animals/Bird.cs
+++ 3.6/ZooScenario/Business Classes/Animals/Bird.cs
@@ -7,7 +7,7 @@
/// <summary>
/// The bird class.
/// </summary>
- public abstract class Bird : Animal
+ public abstract class Bird : Animal, IHatchable
{
/// <summary>
/// A new bird constructor.
@@ -34,6 +34,13 @@
}
/// <summary>
+ /// Hatches a new bird.
+ /// </summary>
+ public void Hatch()
+ {
+ }
+
+ /// <summary>
/// Make the bird move.
/// </summary>
public override void Move()
ZooScenario/Business Classes/Animals/Platypus.cs
Apply the following code changes:
--- 3.5/ZooScenario/Business Classes/Animals/Platypus.cs
+++ 3.6/ZooScenario/Business Classes/Animals/Platypus.cs
@@ -7,7 +7,7 @@
/// <summary>
/// The platypus class.
/// </summary>
- public class Platypus : Mammal
+ public class Platypus : Mammal, IHatchable
{
/// <summary>
/// A new platypus constructor.
@@ -32,6 +32,13 @@
}
/// <summary>
+ /// Hatches a new platypus.
+ /// </summary>
+ public void Hatch()
+ {
+ }
+
+ /// <summary>
/// Make the platypus move.
/// </summary>
public override void Move()
ZooScenario/ZooScenario.csproj
Verify that Visual Studio added the required files to the project:
--- 3.5/ZooScenario/ZooScenario.csproj
+++ 3.6/ZooScenario/ZooScenario.csproj
@@ -94,6 +94,10 @@
</Compile>
<Compile Include="Enums\Direction.cs" />
<Compile Include="Enums\Gender.cs" />
+ <Compile Include="Interfaces\IEater.cs" />
+ <Compile Include="Interfaces\IHatchable.cs" />
+ <Compile Include="Interfaces\IMover.cs" />
+ <Compile Include="Interfaces\IReproducer.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
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.6.
- Compare your filenames, namespaces, signatures, and key values with the code shown above.
Summary
You updated the project from Zoo 3.5 End to Zoo 3.6 End by creating the required files, modifying only the files with meaningful source changes, and verifying the completed application.