Overview
Activity
Update the Zoo project to checkpoint 1.2.
User Story
As a developer, I want to complete the Zoo 1.2 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 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 1.1 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/BirthingRoom.csZooScenario/Business Classes/VendingMachine.cs
Files to update
ZooScenario/Business Classes/Zoo.csZooScenario/MainWindow.xamlZooScenario/MainWindow.xaml.cs
Create New Files
ZooScenario/Business Classes/BirthingRoom.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 birthing room.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class BirthingRoom
{
/// <summary>
/// The current temperature of the birthing room.
/// </summary>
public double Temperature;
/// <summary>
/// The mother animal which is to give birth.
/// </summary>
public Animal Mother;
/// <summary>
/// The doctor for the birthing room.
/// </summary>
public Employee Doctor;
}
}
ZooScenario/Business Classes/VendingMachine.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 vending machine.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class VendingMachine
{
/// <summary>
/// The price of food (per pound).
/// </summary>
public decimal FoodPricePerPound;
/// <summary>
/// The amount of food currently in stock (in pounds).
/// </summary>
public double FoodStock;
/// <summary>
/// The amount of money currently in the vending machine.
/// </summary>
public decimal MoneyBalance;
}
}
Update Existing Files
ZooScenario/Business Classes/Zoo.cs
Apply the following code changes:
--- 1.1/ZooScenario/Business Classes/Zoo.cs
+++ 1.2/ZooScenario/Business Classes/Zoo.cs
@@ -10,6 +10,16 @@
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]
public class Zoo
{
+ /// <summary>
+ /// The zoo's vending machine which allows guests to buy snacks for animals.
+ /// </summary>
+ public VendingMachine AnimalSnackMachine;
+
+ /// <summary>
+ /// The zoo's room for birthing animals.
+ /// </summary>
+ public BirthingRoom BirthArea;
+
/// <summary>
/// The maximum number of guests the zoo can accommodate at a given time.
/// </summary>
ZooScenario/MainWindow.xaml
Apply the following code changes:
--- 1.1/ZooScenario/MainWindow.xaml
+++ 1.2/ZooScenario/MainWindow.xaml
@@ -36,6 +36,7 @@
</Separator>
<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"/>
<!-- End San Diego Zoo buttons -->
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
ZooScenario/MainWindow.xaml.cs
Apply the following code changes:
--- 1.1/ZooScenario/MainWindow.xaml.cs
+++ 1.2/ZooScenario/MainWindow.xaml.cs
@@ -25,6 +25,11 @@
public Zoo ComoZoo;
/// <summary>
+ /// The San Diego Zoo.
+ /// </summary>
+ public Zoo SanDiegoZoo;
+
+ /// <summary>
/// Initializes a new instance of the MainWindow class.
/// </summary>
public MainWindow()
@@ -40,13 +45,22 @@
private void newComoZooButton_Click(object sender, RoutedEventArgs e)
{
this.ComoZoo = new Zoo();
-
+ this.ComoZoo.AnimalSnackMachine = new VendingMachine();
+ this.ComoZoo.BirthArea = new BirthingRoom();
this.ComoZoo.Capacity = 1000;
this.ComoZoo.FeaturedAnimal = new Animal();
this.ComoZoo.LadiesRoom = new Restroom();
this.ComoZoo.MensRoom = new Restroom();
this.ComoZoo.Name = "Como Zoo";
this.ComoZoo.TicketBooth = new Booth();
+
+ this.ComoZoo.BirthArea.Mother = this.ComoZoo.FeaturedAnimal;
+ this.ComoZoo.BirthArea.Temperature = 77.0;
+ this.ComoZoo.BirthArea.Doctor = new Employee();
+
+ this.ComoZoo.AnimalSnackMachine.FoodPricePerPound = 0.75m;
+ this.ComoZoo.AnimalSnackMachine.FoodStock = 250.0;
+ this.ComoZoo.AnimalSnackMachine.MoneyBalance = 42.75m;
this.ComoZoo.FeaturedAnimal.Age = 4;
this.ComoZoo.FeaturedAnimal.Gender = "Female";
@@ -65,6 +79,61 @@
this.ComoZoo.TicketBooth.TicketPrice = 15.00m;
this.ComoZoo.TicketBooth.Attendant.Name = "Sam";
this.ComoZoo.TicketBooth.Attendant.Number = 42;
+
+ this.ComoZoo.BirthArea.Doctor.Name = "Flora";
+ this.ComoZoo.BirthArea.Doctor.Number = 98;
+ }
+
+ /// <summary>
+ /// Creates the San Diego Zoo and related objects.
+ /// </summary>
+ /// <param name="sender">The object that initiated the event.</param>
+ /// <param name="e">The event arguments for the event.</param>
+ private void newSanDiegoZooButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.SanDiegoZoo = new Zoo();
+ this.SanDiegoZoo.AnimalSnackMachine = new VendingMachine();
+ this.SanDiegoZoo.BirthArea = new BirthingRoom();
+ this.SanDiegoZoo.Capacity = 3000;
+ this.SanDiegoZoo.FeaturedAnimal = new Animal();
+ this.SanDiegoZoo.LadiesRoom = new Restroom();
+ this.SanDiegoZoo.MensRoom = new Restroom();
+ this.SanDiegoZoo.Name = "San Diego Zoo";
+ this.SanDiegoZoo.TicketBooth = new Booth();
+
+ // Assign field values of the birth area.
+ this.SanDiegoZoo.BirthArea.Mother = this.SanDiegoZoo.FeaturedAnimal;
+ this.SanDiegoZoo.BirthArea.Temperature = 77.0;
+ this.SanDiegoZoo.BirthArea.Doctor = new Employee();
+
+ // Assign field values of the animal snack machine.
+ this.SanDiegoZoo.AnimalSnackMachine.FoodPricePerPound = 1.20m;
+ this.SanDiegoZoo.AnimalSnackMachine.FoodStock = 3.5;
+ this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance = 56.25m;
+
+ // Assign field values of the featured animal.
+ this.SanDiegoZoo.FeaturedAnimal.Age = 5;
+ this.SanDiegoZoo.FeaturedAnimal.Gender = "Female";
+ this.SanDiegoZoo.FeaturedAnimal.IsPregnant = false;
+ this.SanDiegoZoo.FeaturedAnimal.Name = "Patti";
+ this.SanDiegoZoo.FeaturedAnimal.Type = "Platypus";
+ this.SanDiegoZoo.FeaturedAnimal.Weight = 3.27;
+
+ // Assign field values of the restrooms.
+ this.SanDiegoZoo.LadiesRoom.Capacity = 12;
+ this.SanDiegoZoo.LadiesRoom.Gender = "Female";
+ this.SanDiegoZoo.MensRoom.Capacity = 12;
+ this.SanDiegoZoo.MensRoom.Gender = "Male";
+
+ // Assign field values of the ticket booth.
+ this.SanDiegoZoo.TicketBooth.Attendant = new Employee();
+ this.SanDiegoZoo.TicketBooth.TicketPrice = 25.50m;
+ this.SanDiegoZoo.TicketBooth.Attendant.Name = "Sam";
+ this.SanDiegoZoo.TicketBooth.Attendant.Number = 42;
+
+ // Assign field values of the doctor.
+ this.SanDiegoZoo.BirthArea.Doctor.Name = "Steve";
+ this.SanDiegoZoo.BirthArea.Doctor.Number = 24;
}
}
}
ZooScenario/ZooScenario.csproj
Verify that Visual Studio added the required files to the project:
--- 1.1/ZooScenario/ZooScenario.csproj
+++ 1.2/ZooScenario/ZooScenario.csproj
@@ -68,9 +68,11 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Business Classes\Animal.cs" />
+ <Compile Include="Business Classes\BirthingRoom.cs" />
<Compile Include="Business Classes\Booth.cs" />
<Compile Include="Business Classes\Employee.cs" />
<Compile Include="Business Classes\Restroom.cs" />
+ <Compile Include="Business Classes\VendingMachine.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.2.
- Compare your filenames, namespaces, signatures, and key values with the code shown above.
Summary
You completed Zoo 1.2 by creating the required files, modifying only files with meaningful source changes, and verifying the application.