Overview
Activity
Update the Zoo project to checkpoint 1.3.
User Story
As a developer, I want to complete the Zoo 1.3 checkpoint so the project includes the required programming concepts and behavior.
Acceptance Criteria
- All required new source files 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 8 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 1.2 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/Guest.csZooScenario/Business Classes/Wallet.cs
Files to update
ZooScenario/Business Classes/Animal.csZooScenario/Business Classes/BirthingRoom.csZooScenario/Business Classes/Booth.csZooScenario/Business Classes/Employee.csZooScenario/Business Classes/VendingMachine.csZooScenario/Business Classes/Zoo.csZooScenario/MainWindow.xamlZooScenario/MainWindow.xaml.cs
Create New Files
ZooScenario/Business Classes/Guest.cs
Create this file with the following checkpoint source:
using System;
using System.Collections.Generic;
using System.Text;
namespace ZooScenario
{
/// <summary>
/// The class which is used to represent a guest.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Guest
{
/// <summary>
/// The age of the guest.
/// </summary>
public int Age;
/// <summary>
/// The name of the guest.
/// </summary>
public string Name;
/// <summary>
/// The guest's wallet.
/// </summary>
public Wallet Wallet;
/// <summary>
/// Buys a ticket.
/// </summary>
public void BuyTicket()
{
this.Wallet.RemoveTicketPrice();
}
/// <summary>
/// Visits the zoo.
/// </summary>
public void VisitZoo()
{
this.BuyTicket();
}
}
}
ZooScenario/Business Classes/Wallet.cs
Create this file with the following checkpoint source:
using System;
using System.Collections.Generic;
using System.Text;
namespace ZooScenario
{
/// <summary>
/// The class which is used to represent a wallet.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Wallet
{
/// <summary>
/// The amount of money currently contained within the wallet.
/// </summary>
public decimal MoneyBalance;
/// <summary>
/// Adds money to the wallet.
/// </summary>
public void AddMoney()
{
this.MoneyBalance = this.MoneyBalance + 5.00m;
}
/// <summary>
/// Removes the ticket price from the wallet.
/// </summary>
public void RemoveTicketPrice()
{
this.MoneyBalance = this.MoneyBalance - 15.00m;
}
}
}
Update Existing Files
ZooScenario/Business Classes/Animal.cs
Apply the following code changes:
--- 1.2/ZooScenario/Business Classes/Animal.cs
+++ 1.3/ZooScenario/Business Classes/Animal.cs
@@ -44,5 +44,30 @@
/// The weight of the animal (in pounds).
/// </summary>
public double Weight;
+
+ /// <summary>
+ /// Feeds the animal.
+ /// </summary>
+ public void Eat()
+ {
+ this.Weight = this.Weight + 0.5;
+ this.HappinessLevel = this.HappinessLevel + 2;
+ }
+
+ /// <summary>
+ /// Makes the animal move.
+ /// </summary>
+ public void Move()
+ {
+ this.HappinessLevel = this.HappinessLevel + 1;
+ }
+
+ /// <summary>
+ /// Makes the animal wake up and move.
+ /// </summary>
+ public void WakeUp()
+ {
+ this.Move();
+ }
}
}
ZooScenario/Business Classes/BirthingRoom.cs
Apply the following code changes:
--- 1.2/ZooScenario/Business Classes/BirthingRoom.cs
+++ 1.3/ZooScenario/Business Classes/BirthingRoom.cs
@@ -24,5 +24,22 @@
/// The doctor for the birthing room.
/// </summary>
public Employee Doctor;
+
+ /// <summary>
+ /// Warms the birthing room.
+ /// </summary>
+ public void WarmRoom()
+ {
+ this.Temperature = this.Temperature + 0.5;
+ }
+
+ /// <summary>
+ /// Helps the mother animal rest.
+ /// </summary>
+ public void WakeMotherUp()
+ {
+ this.Mother.WakeUp();
+ this.WarmRoom();
+ }
}
}
ZooScenario/Business Classes/Booth.cs
Apply the following code changes:
--- 1.2/ZooScenario/Business Classes/Booth.cs
+++ 1.3/ZooScenario/Business Classes/Booth.cs
@@ -16,8 +16,22 @@
public Employee Attendant;
/// <summary>
+ /// The amount of money in the booth.
+ /// </summary>
+ public decimal MoneyBalance;
+
+ /// <summary>
/// The price of a ticket.
/// </summary>
public decimal TicketPrice;
+
+ /// <summary>
+ /// Sells a ticket from the booth.
+ /// </summary>
+ public void SellTicket()
+ {
+ this.MoneyBalance = this.MoneyBalance + this.TicketPrice;
+ this.Attendant.SellTicket();
+ }
}
}
ZooScenario/Business Classes/Employee.cs
Apply the following code changes:
--- 1.2/ZooScenario/Business Classes/Employee.cs
+++ 1.3/ZooScenario/Business Classes/Employee.cs
@@ -11,6 +11,11 @@
public class Employee
{
/// <summary>
+ /// The number of tickets the employee has sold.
+ /// </summary>
+ public int TicketsSold;
+
+ /// <summary>
/// The name of the employee.
/// </summary>
public string Name;
@@ -19,5 +24,20 @@
/// The employee's identification number.
/// </summary>
public int Number;
+
+ /// <summary>
+ /// Sells a ticket.
+ /// </summary>
+ public void SellTicket()
+ {
+ this.TicketsSold = this.TicketsSold + 1;
+ }
+
+ /// <summary>
+ /// Feeds the animal assigned to this employee.
+ /// </summary>
+ public void FeedAnimal()
+ {
+ }
}
}
ZooScenario/Business Classes/VendingMachine.cs
Apply the following code changes:
--- 1.2/ZooScenario/Business Classes/VendingMachine.cs
+++ 1.3/ZooScenario/Business Classes/VendingMachine.cs
@@ -24,5 +24,30 @@
/// The amount of money currently in the vending machine.
/// </summary>
public decimal MoneyBalance;
+
+ /// <summary>
+ /// Adds a bag of food to the vending machine.
+ /// </summary>
+ public void AddFoodBag()
+ {
+ this.FoodStock = this.FoodStock + 65.0;
+ }
+
+ /// <summary>
+ /// Fills the vending machine.
+ /// </summary>
+ public void FillVendingMachine()
+ {
+ this.AddFoodBag();
+ this.AddFoodBag();
+ }
+
+ /// <summary>
+ /// Adds money to the vending machine.
+ /// </summary>
+ public void AddMoney()
+ {
+ this.MoneyBalance = this.MoneyBalance + 5.00m;
+ }
}
}
ZooScenario/Business Classes/Zoo.cs
Apply the following code changes:
--- 1.2/ZooScenario/Business Classes/Zoo.cs
+++ 1.3/ZooScenario/Business Classes/Zoo.cs
@@ -49,5 +49,53 @@
/// The zoo's ticket booth.
/// </summary>
public Booth TicketBooth;
+
+ /// <summary>
+ /// The zoo's current visitor.
+ /// </summary>
+ public Guest Visitor;
+
+ /// <summary>
+ /// Opens the zoo for a visitor.
+ /// </summary>
+ public void OpenForVisitor()
+ {
+ this.SellTicket();
+ this.FeaturedAnimal.WakeUp();
+ }
+
+ /// <summary>
+ /// Sells a ticket to the visitor.
+ /// </summary>
+ public void SellTicket()
+ {
+ this.Visitor.BuyTicket();
+ this.TicketBooth.SellTicket();
+ }
+
+ /// <summary>
+ /// Feeds the featured animal.
+ /// </summary>
+ public void FeedFeaturedAnimal()
+ {
+ this.FeaturedAnimal.Eat();
+ this.AnimalSnackMachine.AddMoney();
+ }
+
+ /// <summary>
+ /// Prepares the birthing room.
+ /// </summary>
+ public void PrepareBirthingRoom()
+ {
+ this.BirthArea.WakeMotherUp();
+ }
+
+ /// <summary>
+ /// Fills the animal snack machine.
+ /// </summary>
+ public void FillAnimalSnackMachine()
+ {
+ this.AnimalSnackMachine.FillVendingMachine();
+ }
}
}
ZooScenario/MainWindow.xaml
Apply the following code changes:
--- 1.2/ZooScenario/MainWindow.xaml
+++ 1.3/ZooScenario/MainWindow.xaml
@@ -22,6 +22,10 @@
<StackPanel Grid.Row="0" Grid.Column="0" Margin="5">
<!-- Start Como Zoo buttons -->
<Button x:Name="newComoZooButton" Content="New Como Zoo" Click="newComoZooButton_Click"/>
+ <Button x:Name="openComoZooButton" Content="Open Como Zoo" Click="openComoZooButton_Click"/>
+ <Button x:Name="feedComoAnimalButton" Content="Feed Como Animal" Click="feedComoAnimalButton_Click"/>
+ <Button x:Name="prepareComoBirthingRoomButton" Content="Prepare Como Birthing Room" Click="prepareComoBirthingRoomButton_Click"/>
+ <Button x:Name="fillComoVendingMachineButton" Content="Fill Como Vending Machine" Click="fillComoVendingMachineButton_Click"/>
<!-- End Como Zoo buttons -->
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
@@ -37,6 +41,10 @@
<StackPanel Grid.Row="0" Grid.Column="2" Margin="5">
<!-- Start San Diego Zoo buttons -->
<Button x:Name="newSanDiegoZooButton" Content="New San Diego Zoo" Click="newSanDiegoZooButton_Click"/>
+ <Button x:Name="openSanDiegoZooButton" Content="Open San Diego Zoo" Click="openSanDiegoZooButton_Click"/>
+ <Button x:Name="feedSanDiegoAnimalButton" Content="Feed San Diego Animal" Click="feedSanDiegoAnimalButton_Click"/>
+ <Button x:Name="prepareSanDiegoBirthingRoomButton" Content="Prepare San Diego Birthing Room" Click="prepareSanDiegoBirthingRoomButton_Click"/>
+ <Button x:Name="fillSanDiegoVendingMachineButton" Content="Fill San Diego Vending Machine" Click="fillSanDiegoVendingMachineButton_Click"/>
<!-- End San Diego Zoo buttons -->
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
ZooScenario/MainWindow.xaml.cs
Apply the following code changes:
--- 1.2/ZooScenario/MainWindow.xaml.cs
+++ 1.3/ZooScenario/MainWindow.xaml.cs
@@ -53,6 +53,8 @@
this.ComoZoo.MensRoom = new Restroom();
this.ComoZoo.Name = "Como Zoo";
this.ComoZoo.TicketBooth = new Booth();
+ this.ComoZoo.Visitor = new Guest();
+ this.ComoZoo.Visitor.Wallet = new Wallet();
this.ComoZoo.BirthArea.Mother = this.ComoZoo.FeaturedAnimal;
this.ComoZoo.BirthArea.Temperature = 77.0;
@@ -61,6 +63,10 @@
this.ComoZoo.AnimalSnackMachine.FoodPricePerPound = 0.75m;
this.ComoZoo.AnimalSnackMachine.FoodStock = 250.0;
this.ComoZoo.AnimalSnackMachine.MoneyBalance = 42.75m;
+
+ this.ComoZoo.Visitor.Age = 12;
+ this.ComoZoo.Visitor.Name = "Julia";
+ this.ComoZoo.Visitor.Wallet.MoneyBalance = 25.00m;
this.ComoZoo.FeaturedAnimal.Age = 4;
this.ComoZoo.FeaturedAnimal.Gender = "Female";
@@ -76,6 +82,7 @@
this.ComoZoo.MensRoom.Gender = "Male";
this.ComoZoo.TicketBooth.Attendant = new Employee();
+ this.ComoZoo.TicketBooth.MoneyBalance = 0.00m;
this.ComoZoo.TicketBooth.TicketPrice = 15.00m;
this.ComoZoo.TicketBooth.Attendant.Name = "Sam";
this.ComoZoo.TicketBooth.Attendant.Number = 42;
@@ -100,6 +107,8 @@
this.SanDiegoZoo.MensRoom = new Restroom();
this.SanDiegoZoo.Name = "San Diego Zoo";
this.SanDiegoZoo.TicketBooth = new Booth();
+ this.SanDiegoZoo.Visitor = new Guest();
+ this.SanDiegoZoo.Visitor.Wallet = new Wallet();
// Assign field values of the birth area.
this.SanDiegoZoo.BirthArea.Mother = this.SanDiegoZoo.FeaturedAnimal;
@@ -110,6 +119,11 @@
this.SanDiegoZoo.AnimalSnackMachine.FoodPricePerPound = 1.20m;
this.SanDiegoZoo.AnimalSnackMachine.FoodStock = 3.5;
this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance = 56.25m;
+
+ // Assign field values of the visitor.
+ this.SanDiegoZoo.Visitor.Age = 10;
+ this.SanDiegoZoo.Visitor.Name = "Dakota";
+ this.SanDiegoZoo.Visitor.Wallet.MoneyBalance = 35.00m;
// Assign field values of the featured animal.
this.SanDiegoZoo.FeaturedAnimal.Age = 5;
@@ -127,6 +141,7 @@
// Assign field values of the ticket booth.
this.SanDiegoZoo.TicketBooth.Attendant = new Employee();
+ this.SanDiegoZoo.TicketBooth.MoneyBalance = 0.00m;
this.SanDiegoZoo.TicketBooth.TicketPrice = 25.50m;
this.SanDiegoZoo.TicketBooth.Attendant.Name = "Sam";
this.SanDiegoZoo.TicketBooth.Attendant.Number = 42;
@@ -135,5 +150,93 @@
this.SanDiegoZoo.BirthArea.Doctor.Name = "Steve";
this.SanDiegoZoo.BirthArea.Doctor.Number = 24;
}
+
+ /// <summary>
+ /// Opens the Como Zoo for a visitor.
+ /// </summary>
+ /// <param name="sender">The object that initiated the event.</param>
+ /// <param name="e">The event arguments for the event.</param>
+ private void openComoZooButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.ComoZoo.OpenForVisitor();
+ this.informationTextBox.Text = "The Como Zoo is open for " + this.ComoZoo.Visitor.Name + ".";
+ }
+
+ /// <summary>
+ /// Feeds the Como Zoo's featured animal.
+ /// </summary>
+ /// <param name="sender">The object that initiated the event.</param>
+ /// <param name="e">The event arguments for the event.</param>
+ private void feedComoAnimalButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.ComoZoo.FeedFeaturedAnimal();
+ this.informationTextBox.Text = this.ComoZoo.FeaturedAnimal.Name + " has been fed.";
+ }
+
+ /// <summary>
+ /// Prepares the Como Zoo's birthing room.
+ /// </summary>
+ /// <param name="sender">The object that initiated the event.</param>
+ /// <param name="e">The event arguments for the event.</param>
+ private void prepareComoBirthingRoomButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.ComoZoo.PrepareBirthingRoom();
+ this.informationTextBox.Text = "The Como Zoo birthing room is ready.";
+ }
+
+ /// <summary>
+ /// Fills the Como Zoo's animal snack machine.
+ /// </summary>
+ /// <param name="sender">The object that initiated the event.</param>
+ /// <param name="e">The event arguments for the event.</param>
+ private void fillComoVendingMachineButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.ComoZoo.FillAnimalSnackMachine();
+ this.informationTextBox.Text = "The Como Zoo animal snack machine has been filled.";
+ }
+
+ /// <summary>
+ /// Opens the San Diego Zoo for a visitor.
+ /// </summary>
+ /// <param name="sender">The object that initiated the event.</param>
+ /// <param name="e">The event arguments for the event.</param>
+ private void openSanDiegoZooButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.SanDiegoZoo.OpenForVisitor();
+ this.informationTextBox.Text = "The San Diego Zoo is open for " + this.SanDiegoZoo.Visitor.Name + ".";
+ }
+
+ /// <summary>
+ /// Feeds the San Diego Zoo's featured animal.
+ /// </summary>
+ /// <param name="sender">The object that initiated the event.</param>
+ /// <param name="e">The event arguments for the event.</param>
+ private void feedSanDiegoAnimalButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.SanDiegoZoo.FeedFeaturedAnimal();
+ this.informationTextBox.Text = this.SanDiegoZoo.FeaturedAnimal.Name + " has been fed.";
+ }
+
+ /// <summary>
+ /// Prepares the San Diego Zoo's birthing room.
+ /// </summary>
+ /// <param name="sender">The object that initiated the event.</param>
+ /// <param name="e">The event arguments for the event.</param>
+ private void prepareSanDiegoBirthingRoomButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.SanDiegoZoo.PrepareBirthingRoom();
+ this.informationTextBox.Text = "The San Diego Zoo birthing room is ready.";
+ }
+
+ /// <summary>
+ /// Fills the San Diego Zoo's animal snack machine.
+ /// </summary>
+ /// <param name="sender">The object that initiated the event.</param>
+ /// <param name="e">The event arguments for the event.</param>
+ private void fillSanDiegoVendingMachineButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.SanDiegoZoo.FillAnimalSnackMachine();
+ this.informationTextBox.Text = "The San Diego Zoo animal snack machine has been filled.";
+ }
}
}
ZooScenario/ZooScenario.csproj
Verify that Visual Studio added the required files to the project:
--- 1.2/ZooScenario/ZooScenario.csproj
+++ 1.3/ZooScenario/ZooScenario.csproj
@@ -71,8 +71,10 @@
<Compile Include="Business Classes\BirthingRoom.cs" />
<Compile Include="Business Classes\Booth.cs" />
<Compile Include="Business Classes\Employee.cs" />
+ <Compile Include="Business Classes\Guest.cs" />
<Compile Include="Business Classes\Restroom.cs" />
<Compile Include="Business Classes\VendingMachine.cs" />
+ <Compile Include="Business Classes\Wallet.cs" />
<Compile Include="Business Classes\Zoo.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
Check Your Work
- Save all files.
- Build the solution.
- Resolve compiler errors before continuing.
- Run the application.
- Exercise the behavior associated with Zoo 1.3.
- Compare your filenames, namespaces, signatures, and key values with the code shown above.
Summary
You completed Zoo 1.3 by creating the required files, modifying only files with meaningful source changes, and verifying the application.