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.
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.
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.
This checkpoint adds behavior without introducing later-course concepts. The custom methods added here remain parameterless and return void.
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.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.WalletAdd Wallet.cs to the existing Business Classes folder. Keep the current project namespace, XML documentation style, and StyleCop suppression pattern.
C#
public decimal MoneyBalance;Wallet.cs to the Business Classes folderMoneyBalance : decimal fieldGuestC#
public double PortionSize;
public int Age;
public string Name;
public Wallet Wallet;C#
public void Eat()
{
// No state change is needed for this example.
}Guest.cs to the Business Classes folderPortionSize, Age, Name, and the Wallet referenceEat() methodZooC#
public Guest Visitor;Visitor : Guest relationship to Zoo| Value | Como Zoo | San Diego Zoo |
|---|---|---|
Guest |
Darla | Dave |
Age |
11 | 13 |
PortionSize |
1.0 | 1.0 |
Wallet balance |
5.25m | 3.75m |
Wallet in the Como Zoo setup flowWallet in the San Diego Zoo setup flowBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.MainWindow.xaml.cs, set a breakpoint on the closing brace of newComoZooButton_Click by clicking its left margin.F5 to start or continue the application. Click New Como Zoo.Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.this.ComoZoo.Visitor.Name is "Darla".this.ComoZoo.Visitor.Wallet.MoneyBalance is 5.25m.F5 to continue. Stop debugging and remove the breakpoint before the next check.MainWindow.xaml.cs, set a breakpoint on the closing brace of newSanDiegoZooButton_Click by clicking its left margin.F5 to start or continue the application. Click New San Diego Zoo.Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.this.SanDiegoZoo.Visitor.Name is "Dave".this.SanDiegoZoo.Visitor.Wallet.MoneyBalance is 3.75m.new Wallet() rather than a reference to the other visitor’s wallet.F5 to continue. Stop debugging and remove the breakpoint before the next check.RemoveMoney()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.
RemoveMoney() method to WalletWalletBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.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.Wallet, takes no arguments and returns void.this.MoneyBalance starts at 5.25m and becomes 3.25m after subtracting 2.0m.AddMoney()C#
public void AddMoney()
{
this.MoneyBalance += 2.0m;
}AddMoney() to VendingMachineBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.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.void.this.MoneyBalance equal to 0.00m. Follow the addition of 2.0m and confirm the result is 2.00m.SellFood()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.
SellFood() to VendingMachineAddMoney() before reducing FoodStockBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.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.this.AddMoney() is called once. With this.MoneyBalance initially 0.00m, it becomes 2.00m.this.FoodStock initially 0.0, follow the subtraction of 1.0 and confirm it becomes -1.0.C#
public double EatWeightGainPercentage = 0.8;Eat()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.
Animal, add or confirm the field declaration public double EatWeightGainPercentage = 0.8;Eat() methodAnimalBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.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.35.3 for this.Weight. Confirm one call produces approximately 63.54.this.Weight equal to 3.27. Confirm one call produces approximately 5.886.XAML
<Button x:Name="darlaFeedDingoButton" Content="Darla, feed dingo" Click="darlaFeedDingoButton_Click"/>
C#
public void darlaFeedDingoButton_Click(object sender, RoutedEventArgs e)
{
this.ComoZoo.Visitor.Wallet.RemoveMoney();
this.ComoZoo.AnimalSnackMachine.SellFood();
this.ComoZoo.FeaturedAnimal.Eat();
}RemoveMoney() on Darla's walletSellFood() on the Como vending machineEat() on DollyIf 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.
MainWindow.xaml.cs, set a breakpoint on the first statement of darlaFeedDingoButton_Click.New Como Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.Darla, feed dingo. When execution pauses, open Debug > Windows > Watch > Watch 1.this.ComoZoo.Visitor.Wallet.MoneyBalance is 5.25m.this.ComoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.this.ComoZoo.AnimalSnackMachine.FoodStock is 0.0.this.ComoZoo.FeaturedAnimal.Weight is 35.3.F10 once for each of the three method calls, until execution reaches the handler’s closing brace.this.ComoZoo.Visitor.Wallet.MoneyBalance is 3.25m.this.ComoZoo.AnimalSnackMachine.MoneyBalance is 2.00m.this.ComoZoo.AnimalSnackMachine.FoodStock is -1.0.this.ComoZoo.FeaturedAnimal.Weight is approximately 63.54.F5 to continue. Stop debugging and remove the breakpoint before the next check.XAML
<Button x:Name="daveFeedPlatypusButton" Content="Dave, feed platypus" Click="daveFeedPlatypusButton_Click"/>
C#
public void daveFeedPlatypusButton_Click(object sender, RoutedEventArgs e)
{
this.SanDiegoZoo.Visitor.Wallet.RemoveMoney();
this.SanDiegoZoo.AnimalSnackMachine.SellFood();
this.SanDiegoZoo.FeaturedAnimal.Eat();
}MainWindow.xaml.cs, set a breakpoint on the first statement of daveFeedPlatypusButton_Click.New San Diego Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.Dave, feed platypus. When execution pauses, open Debug > Windows > Watch > Watch 1.this.SanDiegoZoo.Visitor.Wallet.MoneyBalance is 3.75m.this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.this.SanDiegoZoo.AnimalSnackMachine.FoodStock is 0.0.this.SanDiegoZoo.FeaturedAnimal.Weight is 3.27.F10 once for each of the three method calls, until execution reaches the handler’s closing brace.this.SanDiegoZoo.Visitor.Wallet.MoneyBalance is 1.75m.this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance is 2.00m.this.SanDiegoZoo.AnimalSnackMachine.FoodStock is -1.0.this.SanDiegoZoo.FeaturedAnimal.Weight is approximately 5.886.F5 to continue. Stop debugging and remove the breakpoint before the next check.Set a breakpoint on:
C#
this.ComoZoo.Visitor.Wallet.RemoveMoney();Darla, feed dingo and stop at the breakpointWallet.RemoveMoney()MoneyBalance before and after the subtractionVendingMachine.SellFood()this.AddMoney() from inside SellFood()AddMoney()VendingMachine.AddMoney()
VendingMachine.SellFood()
MainWindow.darlaFeedDingoButton_Click(...)SellFood() and execute the food-stock subtractionAnimal.Eat()Weight and EatWeightGainPercentage before the calculationAnimal.Eat() and confirm this.Weight is approximately 63.54darlaFeedDingoButton_Click.F11 to enter Wallet.RemoveMoney(). Confirm this.MoneyBalance belongs to Darla’s wallet and begins at 5.25m.Shift+F11 to return to the handler. Press F11 on the SellFood() call, then on its AddMoney() call.Debug > Windows > Call Stack. Confirm VendingMachine.AddMoney is above VendingMachine.SellFood, which is above MainWindow.darlaFeedDingoButton_Click.Shift+F11 to return one method at a time. Return to the handler and step into Animal.Eat(); confirm this.Name is Dolly.F5 to continue. Stop debugging and remove the breakpoint before the next check.AddFoodBag()C#
public void AddFoodBag()
{
this.FoodStock += this.BagSize;
}AddFoodBag() to VendingMachineBagSize; do not duplicate the value inside the UI handlerBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.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.this.BagSize is 65.0.this.FoodStock at 0.0. Follow one addition and confirm 65.0.65.0. Confirm this.FoodStock becomes 130.0.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();
}AddFoodBag() on ComoZoo.AnimalSnackMachineVendingMachine.AddFoodBag().New Como Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.this.FoodStock and confirm 65.0.this.BagSize is 65.0. Press F5 to continue.this.FoodStock is now 130.0.F5 to continue. Stop debugging and remove the breakpoint before the next check.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();
}AddFoodBag() on SanDiegoZoo.AnimalSnackMachineVendingMachine.AddFoodBag().New San Diego Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.this.FoodStock and confirm 65.0.this.BagSize is 65.0. Press F5 to continue.this.FoodStock is now 130.0.F5 to continue. Stop debugging and remove the breakpoint before the next check.this.ComoZoo.AnimalSnackMachine.FoodStock is 0.0this.ComoZoo.AnimalSnackMachine.FoodStock is 65.0this.ComoZoo.AnimalSnackMachine.FoodStock is 130.0New Como Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.Darla, feed dingo once.darlaFeedDingoButton_Click and open Watch.this.ComoZoo.Visitor.Wallet.MoneyBalance is 3.25m.this.ComoZoo.AnimalSnackMachine.MoneyBalance is 2.00m.this.ComoZoo.AnimalSnackMachine.FoodStock is 64.0.this.ComoZoo.FeaturedAnimal.Weight is approximately 63.54.F5 to continue. Stop debugging and remove the breakpoint before the next check.MakePregnant()C#
public void MakePregnant()
{
this.IsPregnant = true;
}MakePregnant() method to AnimalBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.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.this.IsPregnant equal to false. Follow the assignment and confirm it becomes true.Animal object and does not create a different animal.Move()C#
public void Move()
{
}Move() to AnimalBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.Animal.Move(). Confirm its declaration has empty parentheses and return type void.Animal and requires no value from the caller.C#
this.ComoZoo.FeaturedAnimal.MakePregnant();C#
this.SanDiegoZoo.FeaturedAnimal.MakePregnant();MakePregnant() after Dolly is initializedMakePregnant() after Patti is initializedthis.ComoZoo.FeaturedAnimal.MakePregnant(); and this.SanDiegoZoo.FeaturedAnimal.MakePregnant(); rather than directly assigning either animal’s IsPregnant fieldMainWindow.xaml.cs, set a breakpoint on the closing brace of newComoZooButton_Click by clicking its left margin.F5 to start or continue the application. Click New Como Zoo.Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.this.ComoZoo.FeaturedAnimal.IsPregnant is true.F5 to continue. Stop debugging and remove the breakpoint before the next check.MainWindow.xaml.cs, set a breakpoint on the closing brace of newSanDiegoZooButton_Click by clicking its left margin.F5 to start or continue the application. Click New San Diego Zoo.Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.this.SanDiegoZoo.FeaturedAnimal.IsPregnant is true.FeaturedAnimal.MakePregnant() on its own zoo’s animal.F5 to continue. Stop debugging and remove the breakpoint before the next check.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.
| 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() |
CreateComoZoo() in MainWindowMakePregnant() after Dolly is initializedBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.MainWindow.xaml.cs, set a breakpoint on the closing brace of CreateComoZoo by clicking its left margin.F5 to start or continue the application. Click New Como Zoo.Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.this.ComoZoo.BirthArea.InitialTemperature is 77.0.this.ComoZoo.AnimalSnackMachine.FoodStock is 0.0.this.ComoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.this.ComoZoo.FeaturedAnimal.Name is "Dolly".this.ComoZoo.FeaturedAnimal.IsPregnant is true.F5 to continue. Stop debugging and remove the breakpoint before the next check.C#
public void newComoZooButton_Click(object sender, RoutedEventArgs e)
{
this.CreateComoZoo();
}CreateComoZoo()Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.MainWindow.xaml.cs, set a breakpoint on the closing brace of newComoZooButton_Click by clicking its left margin.F5 to start or continue the application. Click New Como Zoo.Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.this.ComoZoo.BirthArea.InitialTemperature is 77.0.this.ComoZoo.AnimalSnackMachine.FoodStock is 0.0.this.ComoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.this.ComoZoo.FeaturedAnimal.Name is "Dolly".this.ComoZoo.FeaturedAnimal.IsPregnant is true.F5 to continue. Stop debugging and remove the breakpoint before the next check.C#
public void CreateSanDiegoZoo()| 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() |
CreateSanDiegoZoo() in MainWindowMakePregnant() after Patti is initializedBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.MainWindow.xaml.cs, set a breakpoint on the closing brace of CreateSanDiegoZoo by clicking its left margin.F5 to start or continue the application. Click New San Diego Zoo.Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.this.SanDiegoZoo.BirthArea.InitialTemperature is 77.0.this.SanDiegoZoo.AnimalSnackMachine.FoodStock is 0.0.this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.this.SanDiegoZoo.FeaturedAnimal.Name is "Patti".this.SanDiegoZoo.FeaturedAnimal.IsPregnant is true.F5 to continue. Stop debugging and remove the breakpoint before the next check.C#
public void newSanDiegoZooButton_Click(object sender, RoutedEventArgs e)
{
this.CreateSanDiegoZoo();
}CreateSanDiegoZoo()Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.MainWindow.xaml.cs, set a breakpoint on the closing brace of newSanDiegoZooButton_Click by clicking its left margin.F5 to start or continue the application. Click New San Diego Zoo.Debug > Windows > Watch > Watch 1. Enter each full expression below in a separate Watch row.this.SanDiegoZoo.BirthArea.InitialTemperature is 77.0.this.SanDiegoZoo.AnimalSnackMachine.FoodStock is 0.0.this.SanDiegoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.this.SanDiegoZoo.FeaturedAnimal.Name is "Patti".this.SanDiegoZoo.FeaturedAnimal.IsPregnant is true.F5 to continue. Stop debugging and remove the breakpoint before the next check.Set a breakpoint on:
C#
this.CreateComoZoo();New Como ZooCreateComoZoo()this.ComoZoo.FeaturedAnimal.MakePregnant();Animal.MakePregnant()IsPregnant before and after the assignmentCode
Animal.MakePregnant()
MainWindow.CreateComoZoo()
MainWindow.newComoZooButton_Click(...)CreateComoZoo()Animal.MakePregnant().Debug > Windows > Call Stack. Read the three application frames: Animal.MakePregnant(), MainWindow.CreateComoZoo() and MainWindow.newComoZooButton_Click(...).Shift+F11 once. Confirm execution returns to CreateComoZoo().Shift+F11 again. Confirm execution returns to newComoZooButton_Click.F5 to continue. Stop debugging and remove the breakpoint before the next check.this.ComoZoo.Visitor.Wallet.MoneyBalance is 3.25mthis.ComoZoo.AnimalSnackMachine.MoneyBalance is 2.00m and this.ComoZoo.AnimalSnackMachine.FoodStock is 64.0this.ComoZoo.FeaturedAnimal.Weight is approximately 63.54 and this.ComoZoo.FeaturedAnimal.IsPregnant is truethis.SanDiegoZoo.Visitor.Wallet.MoneyBalance is 1.75mthis.SanDiegoZoo.AnimalSnackMachine.MoneyBalance is 2.00m and this.SanDiegoZoo.AnimalSnackMachine.FoodStock is 64.0this.SanDiegoZoo.FeaturedAnimal.Weight is approximately 5.886 and this.SanDiegoZoo.FeaturedAnimal.IsPregnant is trueSubmit the completed Zoo 1.3 project according to your instructor's directions.
Code
Wallet.RemoveMoney()
VendingMachine.SellFood()
→ VendingMachine.AddMoney()
Animal.Eat()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.