Zoo 1.2 shifts from working mainly with individual objects to defining the class blueprints those objects use. You will add BirthingRoom and VendingMachine, create Como Zoo objects from those definitions, and reuse the same class design for a separate San Diego Zoo.
A class defines a reusable kind of object. Multiple objects can be created from the same class, and each object can maintain its own state.
Make a copy of your code at the beginning of each week and rename the folder and .sln file to the appropriate week number. Doing so will help you maintain a record of your work and keep a working copy of your code in case you need to revert your changes.
This class structure already exists. Zoo 1.2 extends it.
BirthingRoom and VendingMachine use only the current Zoo 1.2 fields.Zoo contains BirthArea : BirthingRoom and AnimalSnackMachine : VendingMachine.BirthArea.Doctor refers to Flora, number 98.MainWindow contains SanDiegoZoo : Zoo.Define BirthingRoom and add only the current Zoo 1.2 fields and class relationships required by the scenario.
BirthingRoom classBefore you write the new class, use Solution Explorer to add the class file to the ZooScenario project.
ZooScenario project nodeBirthingRoom.cs
Now continue with the class structure for BirthingRoom.
BirthingRoom class into the Business Classes folderInsert the following suppression pattern. Keep the two attributes together in one horizontally scrollable code frame and keep each attribute on one physical source line:
C#
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Event handlers may begin with lower-case letters.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Encapsulation not yet taught.")]BirthingRoom exists, but it does not yet describe the temperature information the current scenario needs.
Add the five current scalar fields shown in the class diagram.
These values belong to one birthing-room object's state. double supports the current fractional values such as 77.0 and 0.5.
Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.BirthingRoom.cs. Confirm the five numeric fields are named BirthingRoom.InitialTemperature, BirthingRoom.MaxTemperature, BirthingRoom.MinTemperature, BirthingRoom.TemperatureIncrease, BirthingRoom.Temperature.double.Animal relationshipA birthing-room object must be able to refer to an animal when the scenario requires one.
Add the current Animal-typed field represented as a class relationship.
Animal is the class/type and also the field/role name. The class relationship describes what a BirthingRoom can reference; it does not create an Animal object.
Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.BirthingRoom.cs. Confirm the declaration public Animal Animal; is inside the class.Animal class and the field name is BirthingRoom.Animal. Declaring this field does not create an animal.Doctor relationshipThe room also needs a reference to the employee serving as the doctor.
Add the current Employee-typed Doctor field.
Doctor field represented by the diagramBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.BirthingRoom.cs declares public Employee Doctor;.BirthingRoom.Doctor uses the existing Employee type. Check Solution Explorer: this task should not have added a separate Doctor.cs class.Connect Zoo to BirthingRoom, then create and configure the Como BirthArea.
BirthArea to ZooDeclaring BirthArea creates the class relationship. It does not create the runtime BirthingRoom object.
BirthArea field to ZooBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.Zoo.cs. Confirm public BirthingRoom BirthArea; is inside the class.Zoo.FeaturedAnimal, Zoo.LadiesRoom, Zoo.MensRoom and Zoo.TicketBooth declarations remain.BirthAreaBirthingRoom object in the existing Como Zoo creation flow and store it in ComoZoo.BirthAreathis.ComoZoo.BirthArea.InitialTemperature = 77.0;, this.ComoZoo.BirthArea.MaxTemperature = 85.0;, this.ComoZoo.BirthArea.MinTemperature = 55.0;, this.ComoZoo.BirthArea.TemperatureIncrease = 0.5;, this.ComoZoo.BirthArea.Temperature = this.ComoZoo.BirthArea.InitialTemperature;this.ComoZoo.BirthArea.Doctor = new Employee();this.ComoZoo.BirthArea.Doctor.Name = "Flora";this.ComoZoo.BirthArea.Doctor.Number = 98;This focused source line adds separate meaning because it shows that the current temperature is initialized from the initial temperature:
C#
this.ComoZoo.BirthArea.Temperature = this.ComoZoo.BirthArea.InitialTemperature;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.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.this.ComoZoo.BirthArea.Doctor.Name is "Flora".this.ComoZoo.BirthArea.Doctor.Number is 98.F5 to continue. Stop debugging and remove the breakpoint before the next check.Define VendingMachine with the current five fields and connect it to Zoo.
VendingMachineBagSize, FoodCapacity, and FoodStock use double. FoodPricePerPound and MoneyBalance use decimal.
ZooScenario/Business Classes/VendingMachine.csBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.VendingMachine.cs. Confirm VendingMachine.BagSize, VendingMachine.FoodCapacity and VendingMachine.FoodStock are declared as double.VendingMachine.FoodPricePerPound and VendingMachine.MoneyBalance are declared as decimal.AnimalSnackMachine to ZooAnimalSnackMachine field to ZooBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.Zoo.cs. Confirm public VendingMachine AnimalSnackMachine; is declared inside the class.Zoo.BirthArea still has type BirthingRoom.Create the Como AnimalSnackMachine and configure the authoritative current state.
VendingMachine object in the existing Como Zoo setup flow and store it in ComoZoo.AnimalSnackMachinethis.ComoZoo.AnimalSnackMachine.BagSize = 65.0;, this.ComoZoo.AnimalSnackMachine.FoodCapacity = 250.0;, this.ComoZoo.AnimalSnackMachine.FoodPricePerPound = 0.75m;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.AnimalSnackMachine.BagSize is 65.0.this.ComoZoo.AnimalSnackMachine.FoodCapacity is 250.0.this.ComoZoo.AnimalSnackMachine.FoodPricePerPound is 0.75m.this.ComoZoo.AnimalSnackMachine.FoodStock is 0.0.this.ComoZoo.AnimalSnackMachine.MoneyBalance is 0.00m.F5 to continue. Stop debugging and remove the breakpoint before the next check.Use the existing Zoo, Animal, Employee, Restroom, Booth, BirthingRoom, and VendingMachine classes to create a separate San Diego object graph.
SanDiegoZooSanDiegoZoo field/referenceBuild > Build Solution. Open View > Error List and resolve any errors introduced by this task.MainWindow.xaml.cs. Confirm both MainWindow.ComoZoo and MainWindow.SanDiegoZoo are fields of type Zoo.The UI markup is not represented by the UML, so use the exact current button source:
XML
<Button x:Name="newSanDiegoZooButton" Content="New San Diego Zoo" Click="newSanDiegoZooButton_Click"/>
MainWindow.xaml. Find the button whose Content is New San Diego Zoo.newSanDiegoZooButton and its Click value is newSanDiegoZooButton_Click.MainWindow.xaml.cs contains a method named newSanDiegoZooButton_Click with the signature shown in this task.The current one-line handler signature is:
C#
private void newSanDiegoZooButton_Click(object sender, RoutedEventArgs e)The event path coordinates creation of a separate object graph. Do not copy a complete finished handler body from this walkthrough.
Create the separate San Diego objects using the same class definitions and the current source values.
this.SanDiegoZoo = new Zoo();. Then assign this.SanDiegoZoo.Name = "San Diego Zoo"; and this.SanDiegoZoo.Capacity = 3000;this.SanDiegoZoo.TicketBooth = new Booth();. Assign this.SanDiegoZoo.TicketBooth.TicketPrice = 25.50m;. Create this.SanDiegoZoo.TicketBooth.Attendant = new Employee();, then assign this.SanDiegoZoo.TicketBooth.Attendant.Name = "Betty"; and this.SanDiegoZoo.TicketBooth.Attendant.Number = 84;this.SanDiegoZoo.LadiesRoom = new Restroom(); and this.SanDiegoZoo.MensRoom = new Restroom();. Assign this.SanDiegoZoo.LadiesRoom.Capacity = 12; and this.SanDiegoZoo.LadiesRoom.Sex = "Female";. Assign this.SanDiegoZoo.MensRoom.Capacity = 12; and this.SanDiegoZoo.MensRoom.Sex = "Male";this.SanDiegoZoo.FeaturedAnimal = new Animal();. Assign this.SanDiegoZoo.FeaturedAnimal.Name = "Patti";, this.SanDiegoZoo.FeaturedAnimal.Sex = "Female";, this.SanDiegoZoo.FeaturedAnimal.Age = 5;, this.SanDiegoZoo.FeaturedAnimal.Weight = 3.27;, this.SanDiegoZoo.FeaturedAnimal.HappinessLevel = 0;, this.SanDiegoZoo.FeaturedAnimal.IsPregnant = true;, this.SanDiegoZoo.FeaturedAnimal.Type = "Platypus";this.SanDiegoZoo.AnimalSnackMachine = new VendingMachine();. Assign this.SanDiegoZoo.AnimalSnackMachine.BagSize = 65.0;, this.SanDiegoZoo.AnimalSnackMachine.FoodCapacity = 250.0;, this.SanDiegoZoo.AnimalSnackMachine.FoodPricePerPound = 1.20m;this.SanDiegoZoo.BirthArea = new BirthingRoom();. Assign this.SanDiegoZoo.BirthArea.InitialTemperature = 77.0;, this.SanDiegoZoo.BirthArea.MaxTemperature = 85.0;, this.SanDiegoZoo.BirthArea.MinTemperature = 55.0;, this.SanDiegoZoo.BirthArea.TemperatureIncrease = 0.5;, this.SanDiegoZoo.BirthArea.Temperature = this.SanDiegoZoo.BirthArea.InitialTemperature;this.SanDiegoZoo.BirthArea.Doctor = new Employee();this.SanDiegoZoo.BirthArea.Doctor.Name = "Steve";this.SanDiegoZoo.BirthArea.Doctor.Number = 24;ComoZoo and SanDiegoZoo are different Zoo objects that use the same class. Their supporting objects hold separate state, so a second zoo does not require duplicate domain classes.
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.Name is "San Diego Zoo".this.SanDiegoZoo.Capacity is 3000.this.SanDiegoZoo.TicketBooth.TicketPrice is 25.50m.this.SanDiegoZoo.TicketBooth.Attendant.Name is "Betty".this.SanDiegoZoo.TicketBooth.Attendant.Number is 84.this.SanDiegoZoo.LadiesRoom.Capacity is 12.this.SanDiegoZoo.LadiesRoom.Sex is "Female".this.SanDiegoZoo.MensRoom.Capacity is 12.this.SanDiegoZoo.MensRoom.Sex is "Male".this.SanDiegoZoo.FeaturedAnimal.Name is "Patti".this.SanDiegoZoo.FeaturedAnimal.Sex is "Female".this.SanDiegoZoo.FeaturedAnimal.Age is 5.this.SanDiegoZoo.FeaturedAnimal.Weight is 3.27.this.SanDiegoZoo.FeaturedAnimal.HappinessLevel is 0.this.SanDiegoZoo.FeaturedAnimal.IsPregnant is true.this.SanDiegoZoo.FeaturedAnimal.Type is "Platypus".this.SanDiegoZoo.AnimalSnackMachine.BagSize is 65.0.this.SanDiegoZoo.AnimalSnackMachine.FoodCapacity is 250.0.this.SanDiegoZoo.AnimalSnackMachine.FoodPricePerPound is 1.20m.this.SanDiegoZoo.BirthArea.InitialTemperature is 77.0.this.SanDiegoZoo.BirthArea.Temperature 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.Doctor.Name is "Steve".this.SanDiegoZoo.BirthArea.Doctor.Number is 24.F5 and remove this breakpoint. Click New Como Zoo and check its values at the end of its creation handler: this.ComoZoo.Name is Como Zoo, this.ComoZoo.Capacity is 1000 and this.ComoZoo.FeaturedAnimal.Name is Dolly.new Zoo() and creates its own related objects instead of assigning this.ComoZoo to this.SanDiegoZoo.BirthingRoom has InitialTemperature, MaxTemperature, MinTemperature, TemperatureIncrease, Animal, Doctor, and Temperature with the current types.VendingMachine has BagSize, FoodCapacity, FoodPricePerPound, FoodStock, and MoneyBalance with the current types.Zoo includes BirthArea : BirthingRoom and AnimalSnackMachine : VendingMachine.MainWindow includes SanDiegoZoo : Zoo.BirthArea has 77.0 / 85.0 / 55.0 / 0.5 / 77.0.BirthArea.Doctor is Flora #98.AnimalSnackMachine has 65.0 / 250.0 / 0.75.San Diego Zoo; Capacity = 3000.25.50; attendant = Betty #84.12 with the supplied Female/Male values.this.SanDiegoZoo.AnimalSnackMachine.BagSize is 65.0; this.SanDiegoZoo.AnimalSnackMachine.FoodCapacity is 250.0; this.SanDiegoZoo.AnimalSnackMachine.FoodPricePerPound is 1.20m.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; this.SanDiegoZoo.BirthArea.Doctor.Name is "Steve"; this.SanDiegoZoo.BirthArea.Doctor.Number is 24.Use the normal build/error-reading and already-taught inspection paths. This page does not claim your project built or ran successfully; verify that in your own project.
Open the Feedback System to continue with the current submission/readiness process.