1.3 Zoo Learning Activity

Zoo Instruction
1.Overview
A Methods

Zoo 1.3 shifts from objects that mainly store state to objects that also perform behavior. You will add parameterless void methods to the existing zoo model, connect those methods to UI actions, and trace execution as methods call other methods.

Fields describe an object's state. Methods describe what an object can do.

B Getting Started
C Make a copy of the Zoo 1.2 [LastName] folder
D Rename the copied folder to Zoo 1.3 [LastName]
E Rename Zoo 1.2 [LastName].sln to Zoo 1.3 [LastName].sln
F Open the copied Zoo 1.3 solution in Visual Studio
G Build the solution before making changes

Keep your Zoo 1.2 checkpoint unchanged. If a later change causes a problem, the previous working checkpoint gives you a known-good source to compare against.

H Starting Point — End of Zoo 1.2

Zoo 1.3 begins with the two-zoo object model already established. The existing project includes the current Zoo, Animal, Employee, Restroom, Booth, BirthingRoom, and VendingMachine classes, plus the Como and San Diego object graphs.

Zoo 1.2 starting class structure for Zoo 1.3. MainWindow references ComoZoo and SanDiegoZoo. Each Zoo references its existing featured animal, restrooms, ticket booth, birthing room, and vending machine. No Zoo 1.3 additions are marked.
Starting structure: authoritative end-of-Zoo-1.2 context.
  • New
  • Changed
  • Removed

This checkpoint adds behavior without introducing later-course concepts. The custom methods added here remain parameterless and return void.

I Acceptance Criteria
  • Each zoo guest is connected to a Wallet.
  • Wallet.RemoveMoney() subtracts the fixed $2.00 feeding amount.
  • VendingMachine.AddMoney() adds $2.00.
  • VendingMachine.SellFood() calls AddMoney() and subtracts 1.0 from FoodStock.
  • Animal.Eat() changes the animal's weight using the current endpoint calculation.
  • The Como and San Diego feed actions call RemoveMoney() → SellFood() → Eat() in that order.
  • VendingMachine.AddFoodBag() increases stock by the current BagSize.
  • Animal.MakePregnant() changes pregnancy state and Animal.Move() represents movement behavior.
  • CreateComoZoo() and CreateSanDiegoZoo() organize the two creation flows.
  • The debugger is used to trace method calls with Step Over, Step Into, Step Out, Continue, and the Call Stack.
Complete a guest feeding transaction
2.Give each zoo guest a wallet
A Add Wallet

Add Wallet.cs to the existing Business Classes folder. Keep the current project namespace, XML documentation style, and StyleCop suppression pattern.

C#

public decimal MoneyBalance;
B Add Wallet.cs to the Business Classes folder
C Add the documented MoneyBalance : decimal field
D Do not add properties or constructors
E Add Guest

C#

public double PortionSize;
public int Age;
public string Name;
public Wallet Wallet;

C#

public void Eat()
{
    // No state change is needed for this example.
}
F Add Guest.cs to the Business Classes folder
G Add PortionSize, Age, Name, and the Wallet reference
H Add the current parameterless Eat() method
I Connect the visitor to Zoo

C#

public Guest Visitor;
Progressive Zoo 1.3 class diagram. Green squares mark the new Guest and Wallet classes, their current fields and Guest Eat method, Zoo Visitor relationship, and Guest Wallet relationship.
Add Guest and Wallet and connect them to Zoo.
  • New
  • Changed
  • Removed
J Add the documented Visitor : Guest relationship to Zoo
K Create the current visitors and wallets
Current visitors and wallets
Value Como Zoo San Diego Zoo
Guest Darla Dave
Age 11 13
PortionSize 1.0 1.0
Wallet balance 5.25m 3.75m
L Create Darla and her Wallet in the Como Zoo setup flow
M Create Dave and his Wallet in the San Diego Zoo setup flow
N Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 In MainWindow.xaml.cs, set a breakpoint on the closing brace of newComoZooButton_Click by clicking its left margin.
3 Press F5 to start or continue the application. Click New Como Zoo.
4 When Visual Studio pauses, open Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.
5 Confirm this.ComoZoo.Visitor.Name is "Darla".
6 Confirm this.ComoZoo.Visitor.Wallet.MoneyBalance is 5.25m.
7 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
8 In MainWindow.xaml.cs, set a breakpoint on the closing brace of newSanDiegoZooButton_Click by clicking its left margin.
9 Press F5 to start or continue the application. Click New San Diego Zoo.
10 When Visual Studio pauses, open Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.
11 Confirm this.SanDiegoZoo.Visitor.Name is "Dave".
12 Confirm this.SanDiegoZoo.Visitor.Wallet.MoneyBalance is 3.75m.
13 Read both creation handlers. Confirm each visitor receives its own new Wallet() rather than a reference to the other visitor’s wallet.
14 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
3.Pay for one feeding transaction
A Add RemoveMoney()
Progressive Wallet class diagram. A green square marks the new RemoveMoney method; MoneyBalance is existing context from the current task.
Add the focused RemoveMoney behavior to Wallet.
  • New
  • Changed
  • Removed

C#

public void RemoveMoney()
{
    this.MoneyBalance -= 2.0m;
}

The m suffix makes 2.0m a decimal. If the balance starts at 5.25m, one call produces 3.25m.

B Add the documented parameterless void RemoveMoney() method to Wallet
C Keep the fixed 2.0m subtraction inside Wallet
D Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 Open Wallet.RemoveMoney() in the source. Follow its statements from top to bottom using the sample values below; this is a paper/source trace, so do not run or edit the application for this check.
3 Confirm the method is declared inside Wallet, takes no arguments and returns void.
4 Using Darla’s wallet as the example, follow the subtraction: this.MoneyBalance starts at 5.25m and becomes 3.25m after subtracting 2.0m.
4.Record money received by the vending machine
A Add AddMoney()
Progressive VendingMachine class diagram. A green square marks the new AddMoney method; existing vending-machine fields are unmarked.
Add AddMoney to VendingMachine.
  • New
  • Changed
  • Removed

C#

public void AddMoney()
{
    this.MoneyBalance += 2.0m;
}
B Add AddMoney() to VendingMachine
C Keep the fixed 2.0m addition inside the vending machine
D Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 Open VendingMachine.AddMoney() in the source. Follow its statements from top to bottom using the sample values below; this is a paper/source trace, so do not run or edit the application for this check.
3 Confirm the declaration takes no arguments and returns void.
4 Start with this.MoneyBalance equal to 0.00m. Follow the addition of 2.0m and confirm the result is 2.00m.
5.Sell one pound of animal food
A Add SellFood()
Progressive VendingMachine class diagram. A green square marks the new SellFood method; AddMoney and the current state fields remain unmarked context.
SellFood becomes a second focused vending-machine behavior.
  • New
  • Changed
  • Removed
MainWindow calls SellFood on the Como vending machine. SellFood calls AddMoney on the same object with a nested method bar. A green square marks SellFood.
SellFood calls another method on the same object before updating food stock.
  • New
  • Changed
  • Removed

C#

public void SellFood()
{
    this.AddMoney();
    this.FoodStock -= 1.0;
}

this.AddMoney() calls another method on the same VendingMachine object. When that call returns, execution continues with the FoodStock subtraction.

B Add SellFood() to VendingMachine
C Call AddMoney() before reducing FoodStock
D Subtract exactly 1.0 from the current food stock
E Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 Open VendingMachine.SellFood() in the source. Follow its statements from top to bottom using the sample values below; this is a paper/source trace, so do not run or edit the application for this check.
3 Confirm this.AddMoney() is called once. With this.MoneyBalance initially 0.00m, it becomes 2.00m.
4 With this.FoodStock initially 0.0, follow the subtraction of 1.0 and confirm it becomes -1.0.
6.Let the featured animal eat
A Add the current weight-gain percentage

C#

public double EatWeightGainPercentage = 0.8;
B Add Eat()
Progressive Animal class diagram. Green squares mark the new EatWeightGainPercentage field and Eat method; existing Animal state remains unmarked context.
Animal gains its first current feeding behavior.
  • New
  • Changed
  • Removed

C#

public void Eat()
{
    this.Weight = this.Weight + this.Weight * this.EatWeightGainPercentage;
}

For Dolly: 35.3 + 35.3 × 0.8 = 63.54.

For Patti: 3.27 + 3.27 × 0.8 = 5.886.

C In Animal, add or confirm the field declaration public double EatWeightGainPercentage = 0.8;
D Add the parameterless void Eat() method
E Keep the weight calculation inside Animal
F Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 Open Animal.Eat() in the source. Follow its statements from top to bottom using the sample values below; this is a paper/source trace, so do not run or edit the application for this check.
3 For Dolly, substitute 35.3 for this.Weight. Confirm one call produces approximately 63.54.
4 For Patti, start a separate trace with this.Weight equal to 3.27. Confirm one call produces approximately 5.886.
7.Connect the Como Zoo feeding action
A Confirm the button

XAML

<Button x:Name="darlaFeedDingoButton" Content="Darla, feed dingo" Click="darlaFeedDingoButton_Click"/>
B Complete the event handler

C#

public void darlaFeedDingoButton_Click(object sender, RoutedEventArgs e)
{
    this.ComoZoo.Visitor.Wallet.RemoveMoney();
    this.ComoZoo.AnimalSnackMachine.SellFood();
    this.ComoZoo.FeaturedAnimal.Eat();
}
The Como feeding event handler calls RemoveMoney on the guest wallet, SellFood on the vending machine, then Eat on Dolly. AddMoney runs inside SellFood on the same vending machine. Green squares mark RemoveMoney, SellFood, and Eat.
Como feed flow: wallet payment → vending-machine sale → animal eating.
  • New
  • Changed
  • Removed
C Call RemoveMoney() on Darla's wallet
D Call SellFood() on the Como vending machine
E Call Eat() on Dolly
F Keep the calls in that order

If FoodStock is 0, one sale produces -1.0. Do not add an if statement in Zoo 1.3; decision logic belongs to a later checkpoint.

G Check Your Work
1 In MainWindow.xaml.cs, set a breakpoint on the first statement of darlaFeedDingoButton_Click.
2 Click New Como Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.
3 Click Darla, feed dingo. When execution pauses, open Debug > Windows > Watch > Watch 1.
4 Confirm this.ComoZoo.Visitor.Wallet.MoneyBalance is 5.25m.
5 Confirm this.ComoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.
6 Confirm this.ComoZoo.AnimalSnackMachine.FoodStock is 0.0.
7 Confirm this.ComoZoo.FeaturedAnimal.Weight is 35.3.
8 Press F10 once for each of the three method calls, until execution reaches the handler’s closing brace.
9 Confirm this.ComoZoo.Visitor.Wallet.MoneyBalance is 3.25m.
10 Confirm this.ComoZoo.AnimalSnackMachine.MoneyBalance is 2.00m.
11 Confirm this.ComoZoo.AnimalSnackMachine.FoodStock is -1.0.
12 Confirm this.ComoZoo.FeaturedAnimal.Weight is approximately 63.54.
13 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
8.Connect the San Diego Zoo feeding action
A Confirm the button

XAML

<Button x:Name="daveFeedPlatypusButton" Content="Dave, feed platypus" Click="daveFeedPlatypusButton_Click"/>
B Complete the event handler

C#

public void daveFeedPlatypusButton_Click(object sender, RoutedEventArgs e)
{
    this.SanDiegoZoo.Visitor.Wallet.RemoveMoney();
    this.SanDiegoZoo.AnimalSnackMachine.SellFood();
    this.SanDiegoZoo.FeaturedAnimal.Eat();
}
C Call the three existing methods through the San Diego object graph
D Keep the transaction order the same as Como Zoo
E Check Your Work
1 In MainWindow.xaml.cs, set a breakpoint on the first statement of daveFeedPlatypusButton_Click.
2 Click New San Diego Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.
3 Click Dave, feed platypus. When execution pauses, open Debug > Windows > Watch > Watch 1.
4 Confirm this.SanDiegoZoo.Visitor.Wallet.MoneyBalance is 3.75m.
5 Confirm this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.
6 Confirm this.SanDiegoZoo.AnimalSnackMachine.FoodStock is 0.0.
7 Confirm this.SanDiegoZoo.FeaturedAnimal.Weight is 3.27.
8 Press F10 once for each of the three method calls, until execution reaches the handler’s closing brace.
9 Confirm this.SanDiegoZoo.Visitor.Wallet.MoneyBalance is 1.75m.
10 Confirm this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance is 2.00m.
11 Confirm this.SanDiegoZoo.AnimalSnackMachine.FoodStock is -1.0.
12 Confirm this.SanDiegoZoo.FeaturedAnimal.Weight is approximately 5.886.
13 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
9.Trace the feeding transaction
A Trace the wallet call
The Como feeding event handler calls RemoveMoney on the guest wallet, SellFood on the vending machine, then Eat on Dolly. AddMoney runs inside SellFood on the same vending machine.
Use this sequence as the map for the debugger trace.
  • New
  • Changed
  • Removed

Set a breakpoint on:

C#

this.ComoZoo.Visitor.Wallet.RemoveMoney();
B Run the application and create a fresh Como Zoo
C Click Darla, feed dingo and stop at the breakpoint
D Step Into Wallet.RemoveMoney()
E Inspect MoneyBalance before and after the subtraction
F Step Out to return to the event handler
G Trace the nested vending-machine call
H Step Into VendingMachine.SellFood()
I Step Into this.AddMoney() from inside SellFood()
J Open the Call Stack while paused in AddMoney()
VendingMachine.AddMoney()
VendingMachine.SellFood()
MainWindow.darlaFeedDingoButton_Click(...)
K Step through the money addition
L Step Out to SellFood() and execute the food-stock subtraction
M Trace the animal call
N Return to the event handler and Step Into Animal.Eat()
O Inspect Dolly's Weight and EatWeightGainPercentage before the calculation
P Execute the calculation in Animal.Eat() and confirm this.Weight is approximately 63.54
Q Press F5 (Continue) when the trace is complete
R Check Your Work
1 During the preceding feeding walkthrough, pause before the wallet call in darlaFeedDingoButton_Click.
2 Press F11 to enter Wallet.RemoveMoney(). Confirm this.MoneyBalance belongs to Darla’s wallet and begins at 5.25m.
3 Press Shift+F11 to return to the handler. Press F11 on the SellFood() call, then on its AddMoney() call.
4 Open Debug > Windows > Call Stack. Confirm VendingMachine.AddMoney is above VendingMachine.SellFood, which is above MainWindow.darlaFeedDingoButton_Click.
5 Press Shift+F11 to return one method at a time. Return to the handler and step into Animal.Eat(); confirm this.Name is Dolly.
6 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
Keep animal-food vending machines stocked
10.Add a food bag to a vending machine
A Add AddFoodBag()
Progressive VendingMachine class diagram. A green square marks the new AddFoodBag method; AddMoney and SellFood are existing Zoo 1.3 context.
Add the vending-machine refill behavior.
  • New
  • Changed
  • Removed

C#

public void AddFoodBag()
{
    this.FoodStock += this.BagSize;
}
B Add AddFoodBag() to VendingMachine
C Use the current machine's BagSize; do not duplicate the value inside the UI handler
D Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 Open VendingMachine.AddFoodBag() in the source. Follow its statements from top to bottom using the sample values below; this is a paper/source trace, so do not run or edit the application for this check.
3 Confirm this.BagSize is 65.0.
4 Start this.FoodStock at 0.0. Follow one addition and confirm 65.0.
5 Follow a second call using the new stock of 65.0. Confirm this.FoodStock becomes 130.0.
11.Refill the Como Zoo vending machine
A Confirm the button and handler
MainWindow calls AddFoodBag on the Como vending machine. Its method bar shows the refill behavior executing. A green square marks AddFoodBag.
The UI requests the refill; the vending machine owns the stock calculation.
  • New
  • Changed
  • Removed

XAML

<Button x:Name="floraFillVendingMachineButton" Content="Flora, fill vending machine" Click="floraFillVendingMachineButton_Click"/>

C#

public void floraFillVendingMachineButton_Click(object sender, RoutedEventArgs e)
{
    this.ComoZoo.AnimalSnackMachine.AddFoodBag();
}
B Call AddFoodBag() on ComoZoo.AnimalSnackMachine
C Check Your Work
1 Set a breakpoint on the closing brace of VendingMachine.AddFoodBag().
2 Click New Como Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.
3 Click this zoo’s refill button once. At the breakpoint, inspect this.FoodStock and confirm 65.0.
4 Confirm this.BagSize is 65.0. Press F5 to continue.
5 Click the same refill button again. At the breakpoint confirm this.FoodStock is now 130.0.
6 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
12.Refill the San Diego Zoo vending machine
A Confirm the button and handler

XAML

<Button x:Name="bettyFillVendingMachineButton" Content="Betty, fill vending machine" Click="bettyFillVendingMachineButton_Click"/>

C#

public void bettyFillVendingMachineButton_Click(object sender, RoutedEventArgs e)
{
    this.SanDiegoZoo.AnimalSnackMachine.AddFoodBag();
}
B Call AddFoodBag() on SanDiegoZoo.AnimalSnackMachine
C Check Your Work
1 Set a breakpoint on the closing brace of VendingMachine.AddFoodBag().
2 Click New San Diego Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.
3 Click this zoo’s refill button once. At the breakpoint, inspect this.FoodStock and confirm 65.0.
4 Confirm this.BagSize is 65.0. Press F5 to continue.
5 Click the same refill button again. At the breakpoint confirm this.FoodStock is now 130.0.
6 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
13.Verify repeated refills
A Refill more than once
B Create a fresh Como Zoo and confirm this.ComoZoo.AnimalSnackMachine.FoodStock is 0.0
C Refill once and confirm this.ComoZoo.AnimalSnackMachine.FoodStock is 65.0
D Refill again and confirm this.ComoZoo.AnimalSnackMachine.FoodStock is 130.0
E Combine refill and feed
F Create a fresh Como Zoo
G Refill once
H Feed Dolly once
I Check Your Work
1 Click New Como Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.
2 Refill the Como machine once, then click Darla, feed dingo once.
3 Pause at the closing brace of darlaFeedDingoButton_Click and open Watch.
4 Confirm this.ComoZoo.Visitor.Wallet.MoneyBalance is 3.25m.
5 Confirm this.ComoZoo.AnimalSnackMachine.MoneyBalance is 2.00m.
6 Confirm this.ComoZoo.AnimalSnackMachine.FoodStock is 64.0.
7 Confirm this.ComoZoo.FeaturedAnimal.Weight is approximately 63.54.
8 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
Let zoo objects perform focused behaviors
14.Change pregnancy state through behavior
A Add MakePregnant()
Progressive Animal class diagram. A green square marks the new MakePregnant method; current weight and feeding behavior remain unmarked context.
Add pregnancy-state behavior to Animal.
  • New
  • Changed
  • Removed

C#

public void MakePregnant()
{
    this.IsPregnant = true;
}
B Add the documented parameterless void MakePregnant() method to Animal
C Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 Open Animal.MakePregnant() in the source. Follow its statements from top to bottom using the sample values below; this is a paper/source trace, so do not run or edit the application for this check.
3 Start with this.IsPregnant equal to false. Follow the assignment and confirm it becomes true.
4 Confirm the method changes the current Animal object and does not create a different animal.
15.Represent animal movement as behavior
A Add Move()
Progressive Animal class diagram. A green square marks the new Move method; Eat and MakePregnant are existing Zoo 1.3 behavior.
Add movement as an Animal-owned behavior.
  • New
  • Changed
  • Removed

C#

public void Move()
{
}
B Add Move() to Animal
C Leave the body empty for Zoo 1.3
D Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 Open Animal.Move(). Confirm its declaration has empty parentheses and return type void.
3 Follow the method body supplied in this task. Confirm it belongs inside Animal and requires no value from the caller.
16.Use MakePregnant() when creating the featured animals
A Call the behavior for Dolly
The New Como Zoo event handler calls CreateComoZoo on the same MainWindow object. CreateComoZoo calls MakePregnant on Dolly. The nested method bars show the callers remaining active. A green square marks CreateComoZoo.
The creation method requests the animal's pregnancy-state behavior.
  • New
  • Changed
  • Removed

C#

this.ComoZoo.FeaturedAnimal.MakePregnant();
B Call the behavior for Patti

C#

this.SanDiegoZoo.FeaturedAnimal.MakePregnant();
C Call MakePregnant() after Dolly is initialized
D Call MakePregnant() after Patti is initialized
E In MainWindow, call this.ComoZoo.FeaturedAnimal.MakePregnant(); and this.SanDiegoZoo.FeaturedAnimal.MakePregnant(); rather than directly assigning either animal’s IsPregnant field
F Check Your Work
1 In MainWindow.xaml.cs, set a breakpoint on the closing brace of newComoZooButton_Click by clicking its left margin.
2 Press F5 to start or continue the application. Click New Como Zoo.
3 When Visual Studio pauses, open Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.
4 Confirm this.ComoZoo.FeaturedAnimal.IsPregnant is true.
5 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
6 In MainWindow.xaml.cs, set a breakpoint on the closing brace of newSanDiegoZooButton_Click by clicking its left margin.
7 Press F5 to start or continue the application. Click New San Diego Zoo.
8 When Visual Studio pauses, open Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.
9 Confirm this.SanDiegoZoo.FeaturedAnimal.IsPregnant is true.
10 Read both setup paths and confirm each calls FeaturedAnimal.MakePregnant() on its own zoo’s animal.
11 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
Organize zoo creation into focused application actions
17.Create the Como Zoo through a focused method
A Add the creation method
Progressive class diagram. Green squares mark the new MainWindow CreateComoZoo and CreateSanDiegoZoo methods. Existing Zoo and FeaturedAnimal relationships provide context.
Move the two large setup flows into focused MainWindow methods.
  • New
  • Changed
  • Removed

C#

public void CreateComoZoo()

Move the existing Como creation statements into this method. Do not rewrite the entire object graph from memory; preserve the current working relationships and values.

Current Como Zoo state
Area Current state
Zoo this.ComoZoo.Name is "Como Zoo"; this.ComoZoo.Capacity is 1000
Ticket booth this.ComoZoo.TicketBooth.TicketPrice is 15.00m; this.ComoZoo.TicketBooth.Attendant.Name is "Sam"; this.ComoZoo.TicketBooth.Attendant.Number is 42
Visitor Darla, age 11, wallet 5.25m, portion size 1.0
Vending machine this.ComoZoo.AnimalSnackMachine.BagSize = 65.0, this.ComoZoo.AnimalSnackMachine.FoodCapacity = 250.0, this.ComoZoo.AnimalSnackMachine.FoodPricePerPound = 0.75m
Birthing room this.ComoZoo.BirthArea.InitialTemperature is 77.0; this.ComoZoo.BirthArea.MaxTemperature is 85.0; this.ComoZoo.BirthArea.MinTemperature is 55.0; this.ComoZoo.BirthArea.TemperatureIncrease is 0.5; this.ComoZoo.BirthArea.Temperature is 77.0
Doctor Flora, number 98
Restrooms Ladies: capacity 4, Female; Mens: capacity 4, Male
Featured animal Dolly, Female, age 4, weight 35.3, happiness 0, type Dingo, pregnancy through MakePregnant()
B Create CreateComoZoo() in MainWindow
C Move the existing Como object-creation statements into the method
D Preserve the current relationships and values shown above
E Call MakePregnant() after Dolly is initialized
F Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 In MainWindow.xaml.cs, set a breakpoint on the closing brace of CreateComoZoo by clicking its left margin.
3 Press F5 to start or continue the application. Click New Como Zoo.
4 When Visual Studio pauses, open Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.
5 Confirm this.ComoZoo.BirthArea.InitialTemperature is 77.0.
6 Confirm this.ComoZoo.AnimalSnackMachine.FoodStock is 0.0.
7 Confirm this.ComoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.
8 Confirm this.ComoZoo.FeaturedAnimal.Name is "Dolly".
9 Confirm this.ComoZoo.FeaturedAnimal.IsPregnant is true.
10 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
18.Connect the New Como Zoo control
A Simplify the event handler

C#

public void newComoZooButton_Click(object sender, RoutedEventArgs e)
{
    this.CreateComoZoo();
}
B Replace the detailed Como setup inside the event handler with the call to CreateComoZoo()
C Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 In MainWindow.xaml.cs, set a breakpoint on the closing brace of newComoZooButton_Click by clicking its left margin.
3 Press F5 to start or continue the application. Click New Como Zoo.
4 When Visual Studio pauses, open Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.
5 Confirm this.ComoZoo.BirthArea.InitialTemperature is 77.0.
6 Confirm this.ComoZoo.AnimalSnackMachine.FoodStock is 0.0.
7 Confirm this.ComoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.
8 Confirm this.ComoZoo.FeaturedAnimal.Name is "Dolly".
9 Confirm this.ComoZoo.FeaturedAnimal.IsPregnant is true.
10 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
19.Create the San Diego Zoo through a focused method
A Add the creation method

C#

public void CreateSanDiegoZoo()
Current San Diego Zoo state
Area Current state
Zoo this.SanDiegoZoo.Name is "San Diego Zoo"; this.SanDiegoZoo.Capacity is 3000
Ticket booth this.SanDiegoZoo.TicketBooth.TicketPrice is 25.50m; this.SanDiegoZoo.TicketBooth.Attendant.Name is "Betty"; this.SanDiegoZoo.TicketBooth.Attendant.Number is 84
Visitor Dave, age 13, wallet 3.75m, portion size 1.0
Vending machine this.SanDiegoZoo.AnimalSnackMachine.BagSize = 65.0, this.SanDiegoZoo.AnimalSnackMachine.FoodCapacity = 250.0, this.SanDiegoZoo.AnimalSnackMachine.FoodPricePerPound = 1.20m
Birthing room this.SanDiegoZoo.BirthArea.InitialTemperature is 77.0; this.SanDiegoZoo.BirthArea.MaxTemperature is 85.0; this.SanDiegoZoo.BirthArea.MinTemperature is 55.0; this.SanDiegoZoo.BirthArea.TemperatureIncrease is 0.5; this.SanDiegoZoo.BirthArea.Temperature is 77.0
Doctor Steve, number 24
Restrooms Ladies: capacity 12, Female; Mens: capacity 12, Male
Featured animal Patti, Female, age 5, weight 3.27, happiness 0, type Platypus, pregnancy through MakePregnant()
B Create CreateSanDiegoZoo() in MainWindow
C Move the existing San Diego object-creation statements into the method
D Preserve the current relationships and values shown above
E Call MakePregnant() after Patti is initialized
F Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 In MainWindow.xaml.cs, set a breakpoint on the closing brace of CreateSanDiegoZoo by clicking its left margin.
3 Press F5 to start or continue the application. Click New San Diego Zoo.
4 When Visual Studio pauses, open Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.
5 Confirm this.SanDiegoZoo.BirthArea.InitialTemperature is 77.0.
6 Confirm this.SanDiegoZoo.AnimalSnackMachine.FoodStock is 0.0.
7 Confirm this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.
8 Confirm this.SanDiegoZoo.FeaturedAnimal.Name is "Patti".
9 Confirm this.SanDiegoZoo.FeaturedAnimal.IsPregnant is true.
10 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
20.Connect the New San Diego Zoo control
A Simplify the event handler

C#

public void newSanDiegoZooButton_Click(object sender, RoutedEventArgs e)
{
    this.CreateSanDiegoZoo();
}
B Replace the detailed San Diego setup inside the event handler with the call to CreateSanDiegoZoo()
C Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.
2 In MainWindow.xaml.cs, set a breakpoint on the closing brace of newSanDiegoZooButton_Click by clicking its left margin.
3 Press F5 to start or continue the application. Click New San Diego Zoo.
4 When Visual Studio pauses, open Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.
5 Confirm this.SanDiegoZoo.BirthArea.InitialTemperature is 77.0.
6 Confirm this.SanDiegoZoo.AnimalSnackMachine.FoodStock is 0.0.
7 Confirm this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.
8 Confirm this.SanDiegoZoo.FeaturedAnimal.Name is "Patti".
9 Confirm this.SanDiegoZoo.FeaturedAnimal.IsPregnant is true.
10 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
21.Trace a method called from another method
A Enter the creation method
The New Como Zoo event handler calls CreateComoZoo on the same MainWindow object. CreateComoZoo calls MakePregnant on Dolly. The nested method bars show the callers remaining active.
Use this sequence as the map for the zoo-creation debugger trace.
  • New
  • Changed
  • Removed

Set a breakpoint on:

C#

this.CreateComoZoo();
B Run the application and click New Como Zoo
C Step Into CreateComoZoo()
D Continue until execution reaches this.ComoZoo.FeaturedAnimal.MakePregnant();
E Enter the animal method
F Step Into Animal.MakePregnant()
G Inspect IsPregnant before and after the assignment
H Open the Call Stack

Code

Animal.MakePregnant()
MainWindow.CreateComoZoo()
MainWindow.newComoZooButton_Click(...)
I Step Out to return to CreateComoZoo()
J Step Out again to return to the event handler
K Check Your Work
1 Repeat the preceding trace until paused inside Animal.MakePregnant().
2 Open Debug > Windows > Call Stack. Read the three application frames: Animal.MakePregnant(), MainWindow.CreateComoZoo() and MainWindow.newComoZooButton_Click(...).
3 Press Shift+F11 once. Confirm execution returns to CreateComoZoo().
4 Press Shift+F11 again. Confirm execution returns to newComoZooButton_Click.
5 Press F5 to continue. Stop debugging and remove the breakpoint before the next check.
22.Finish and Submit
A Final Como transaction check
B Create a fresh Como Zoo
C Refill the vending machine once
D Feed Dolly once
E Confirm this.ComoZoo.Visitor.Wallet.MoneyBalance is 3.25m
F Confirm this.ComoZoo.AnimalSnackMachine.MoneyBalance is 2.00m and this.ComoZoo.AnimalSnackMachine.FoodStock is 64.0
G Confirm this.ComoZoo.FeaturedAnimal.Weight is approximately 63.54 and this.ComoZoo.FeaturedAnimal.IsPregnant is true
H Final San Diego transaction check
I Create a fresh San Diego Zoo
J Refill the vending machine once
K Feed Patti once
L Confirm this.SanDiegoZoo.Visitor.Wallet.MoneyBalance is 1.75m
M Confirm this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance is 2.00m and this.SanDiegoZoo.AnimalSnackMachine.FoodStock is 64.0
N Confirm this.SanDiegoZoo.FeaturedAnimal.Weight is approximately 5.886 and this.SanDiegoZoo.FeaturedAnimal.IsPregnant is true
O Debugger check
P Confirm you can set a breakpoint
Q Confirm you can Step Over, Step Into, and Step Out
R Confirm you can Continue with F5
S Confirm you can inspect state before and after a method
T Confirm you can use the Call Stack to identify nested calls
U Build the solution and resolve compilation errors and project-style warnings introduced by your work
V Stop debugging and save all files

Submit the completed Zoo 1.3 project according to your instructor's directions.

23.Checkpoint Summary
Final Zoo 1.3 class diagram. Green squares mark all new Zoo 1.3 structural items: Guest, Wallet, Zoo Visitor and Guest Wallet relationships; Wallet RemoveMoney; Animal EatWeightGainPercentage, Eat, MakePregnant, and Move; VendingMachine AddFoodBag, AddMoney, and SellFood; and MainWindow CreateComoZoo and CreateSanDiegoZoo. Existing Zoo 1.2 context is unmarked. There are no Changed or Removed structural items.
Final structural delta: New items only; Changed none; Removed none.
  • New
  • Changed
  • Removed
A Feeding transaction

Code

Wallet.RemoveMoney()
VendingMachine.SellFood()
    → VendingMachine.AddMoney()
Animal.Eat()
B Other current behaviors

Code

VendingMachine.AddFoodBag()
Animal.MakePregnant()
Animal.Move()
MainWindow.CreateComoZoo()
MainWindow.CreateSanDiegoZoo()

All custom methods introduced at this checkpoint remain parameterless void methods. Parameters, returned values, and decision logic are reserved for later checkpoints.