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 Build
2 Confirm ComoZoo.Visitor.Name = "Darla" and ComoZoo.Visitor.Wallet.MoneyBalance = 5.25m
3 Confirm SanDiegoZoo.Visitor.Name = "Dave" and SanDiegoZoo.Visitor.Wallet.MoneyBalance = 3.75m
4 Confirm the two guests reference separate Wallet objects
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 Build
2 Confirm RemoveMoney() belongs to Wallet
3 Confirm it subtracts exactly 2.0m and does not return a value
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 Build
2 Confirm the method changes the current vending machine's MoneyBalance
3 Confirm it has no custom parameters and returns void
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
Sequence diagram for one vending-machine sale. A green square marks the SellFood call. SellFood calls AddMoney on the same vending-machine object, then the machine reduces FoodStock.
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 Build
2 Confirm SellFood() calls AddMoney()
3 Confirm one sale adds 2.0m to money and removes 1.0 pound of food
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 Add or confirm EatWeightGainPercentage = 0.8 in Animal
D Add the parameterless void Eat() method
E Keep the weight calculation inside Animal
F Check Your Work
1 Build
2 Confirm Dolly changes from 35.3 to 63.54 after one call
3 Confirm Patti changes from 3.27 to 5.886 after one call
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();
}
Sequence diagram for the Como feeding transaction. Green squares mark the UI-requested calls RemoveMoney, SellFood, and Eat. SellFood makes the nested AddMoney call on the same vending-machine object.
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 From a fresh Como Zoo without refilling, confirm Darla changes 5.25 → → 3.25
2 Confirm vending money changes 0 → → 2.00
3 Confirm food stock changes 0 → → -1.0
4 Confirm Dolly changes 35.3 → → 63.54
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 From a fresh San Diego Zoo without refilling, confirm Dave changes 3.75 → → 1.75
2 Confirm vending money changes 0 → → 2.00
3 Confirm food stock changes 0 → → -1.0
4 Confirm Patti changes 3.27 → → 5.886
9.Trace the feeding transaction
A Trace the wallet call
Method-call trace map for the Como feeding transaction. MainWindow calls Wallet.RemoveMoney, VendingMachine.SellFood, and Animal.Eat; SellFood calls AddMoney 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 and confirm Weight = 63.54
Q Press F5 (Continue) when the trace is complete
R Check Your Work
  • You can explain how the event handler calls three different object behaviors.
  • You can identify the nested SellFood() → → AddMoney() path in the Call Stack.
  • You can use Step Out to return to a caller.
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
  • Build.
  • With BagSize = 65 and FoodStock = 0, one call produces 65.
  • A second call produces 130.
11.Refill the Como Zoo vending machine
A Confirm the button and handler
Sequence diagram for the refill action. A green square marks MainWindow calling AddFoodBag on the current VendingMachine, which updates FoodStock from its current value using BagSize.
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 Create a fresh Como Zoo
2 Confirm FoodStock = 0, click the refill button once, and confirm FoodStock = 65
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 Create a fresh San Diego Zoo
2 Confirm FoodStock = 0, click the refill button once, and confirm FoodStock = 65
13.Verify repeated refills
A Refill more than once
B Create a fresh Como Zoo and confirm FoodStock = 0
C Refill once and confirm FoodStock = 65
D Refill again and confirm FoodStock = 130
E Combine refill and feed
F Create a fresh Como Zoo
G Refill once
H Feed Dolly once
I Check Your Work
  • Darla wallet = 3.25.
  • Como vending MoneyBalance = 2.00.
  • Como vending FoodStock = 64.0.
  • Dolly Weight = 63.54.
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 Build
2 Confirm the method changes the current animal's IsPregnant field to true
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 Build
2 Confirm the method is parameterless and returns void
16.Use MakePregnant() when creating the featured animals
A Call the behavior for Dolly
Sequence diagram showing MainWindow's zoo-creation method calling MakePregnant on the current featured Animal. A green square marks the CreateComoZoo call in this focused diagram.
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 Do not directly assign IsPregnant = true from MainWindow for these actions
F Check Your Work
1 Create each zoo
2 Confirm both featured animals have IsPregnant = true
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 Name = "Como Zoo", Capacity = 1000
Ticket booth TicketPrice = 15.00m, attendant Sam, number 42
Visitor Darla, age 11, wallet 5.25m, portion size 1.0
Vending machine BagSize = 65.0, FoodCapacity = 250.0, FoodPricePerPound = 0.75m
Birthing room InitialTemperature = 77.0, max 85.0, min 55.0, increase 0.5, current temperature = initial temperature
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 Build
2 Confirm Como InitialTemperature = 77.0
3 Confirm vending FoodStock and MoneyBalance begin at their default numeric value 0
4 Confirm Dolly is pregnant through MakePregnant()
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 Build and run
2 Click New Como Zoo and confirm the complete zoo is still created
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 Name = "San Diego Zoo", Capacity = 3000
Ticket booth TicketPrice = 25.50m, attendant Betty, number 84
Visitor Dave, age 13, wallet 3.75m, portion size 1.0
Vending machine BagSize = 65.0, FoodCapacity = 250.0, FoodPricePerPound = 1.20m
Birthing room InitialTemperature = 77.0, max 85.0, min 55.0, increase 0.5, current temperature = initial temperature
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 Build
2 Confirm San Diego InitialTemperature = 77.0
3 Confirm Patti is pregnant through MakePregnant()
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 Build and run
2 Click New San Diego Zoo and confirm the complete zoo is still created
21.Trace a method called from another method
A Enter the creation method
Method-call trace map for zoo creation. The New Como Zoo event enters MainWindow.CreateComoZoo, which calls Animal.MakePregnant on the featured animal.
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
  • You can explain the three-level call path from the UI event to the animal method.
  • You can identify the current method and its callers in the Call Stack.
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 Darla wallet = 3.25
F Confirm vending MoneyBalance = 2.00 and FoodStock = 64.0
G Confirm Dolly Weight = 63.54 and IsPregnant = 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 Dave wallet = 1.75
M Confirm vending MoneyBalance = 2.00 and FoodStock = 64.0
N Confirm Patti Weight = 5.886 and IsPregnant = 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.