In this activity, you will start from the provided Zoo 1.1 LastName1.1 LastName project and complete the first version of the Como Zoo object model.
The manager of Como Zoo has asked for the first version of a program that stores basic zoo information. This version will create the main Como Zoo object and connect it to the first objects the zoo needs to track: a featured animal, restrooms, a ticket booth, and the employee working at the booth.
This checkpoint gives the rest of the project a foundation. Later checkpoints will build on these objects and add more behavior.




Problem: Before adding any zoo code, confirm that the New Como Zoo button is already connected to code that runs when the button is clicked.
Solution: Open ZooScenario/MainWindow.xaml, locate the New Como Zoo button, and double-click it. Visual Studio should open MainWindow.xaml.cs and place the cursor inside the existing newComoZooButton_Click event handler.

What Is an Event Handler?: An event handler is a method that runs when something happens in the application. Here, clicking the New Como Zoo button causes Visual Studio to call newComoZooButton_Click. The method can be empty and still run when the button is clicked.
Need a Refresher?: Review these previously introduced topics if you need help:
What This Means: The button is already connected to its event handler. A breakpoint pauses the program so you can inspect what is happening, but the breakpoint is not required for the button or the event handler to work.
Problem: The MainWindow already has a ComoZoo field, but that field does not point to a real Zoo object yet.
Solution: Inside the newComoZooButton_Click event handler, create one new Zoo object and store it in this.ComoZoo. Place it near the start of the method, before any code that uses this.ComoZoo.
Reading the Diagram: Diagram markers show what was added during the current task. Use the Options menu to switch between the color marker and the lettered accessible marker.
N — New: Added during the current task.// Create an instance of the Zoo class.
this.ComoZoo = new Zoo();What This Code Does: This line creates one Zoo object in memory. The this.ComoZoo = part saves a reference to that object so the rest of the method can keep filling in information for the same zoo. The comment above the line labels this part of the event handler so the object-creation code is easy to distinguish from the field assignments that follow.


Need a Refresher?: Review these previously introduced topics if you need help:
What This Means: Once this line runs, this.ComoZoo is no longer null. It now points to the zoo object that the rest of this checkpoint will fill in.
Problem: The zoo object now exists, but its Capacity field still has its default value.
Solution: Give the existing zoo object a capacity value. Add this after this.ComoZoo has been created, near the other zoo field assignments.
// Assign field values of Como Zoo.
this.ComoZoo.Capacity = 1000;Understanding the Change: This line does not create another object. It follows the reference stored in this.ComoZoo and fills in the Capacity field on the existing zoo object.

Need a Refresher?: Review these previously introduced topics if you need help:
Why You Are Trying This: Before moving on, intentionally create a common programming mistake so you can see why the order of these statements matters. The line this.ComoZoo = new Zoo(); must run before the capacity assignment. Otherwise, this.ComoZoo is still null, and the program cannot assign a capacity to a zoo object that does not exist.
You will temporarily comment out the object-creation line to observe the error. Restore the line before continuing to the next task.
Problem: Como Zoo needs an animal to showcase, but the zoo does not have an Animal object assigned yet.
Solution: Create one Animal object and store it in the zoo's FeaturedAnimal field. Add this after this.ComoZoo exists. It may be grouped with the other object-creation lines.
// Create the featured animal.
this.ComoZoo.FeaturedAnimal = new Animal();What This Code Does: This gives the zoo a reference to an animal object. Later, when you write this.ComoZoo.FeaturedAnimal.Age, the program starts with the zoo, follows its FeaturedAnimal reference, and then fills in that animal's age.
What You Accomplished: The zoo now has a featured animal object. The next lines will not create another animal; they will fill in fields on the animal object you just assigned.
Problem: The zoo object still needs its main related objects and its name.
Solution: Create the restroom and ticket booth objects, and assign the zoo's name. Add these lines after the zoo object exists. The restroom and booth objects must be created before you assign values to their fields later.
Focused Diagram: To keep larger diagrams readable, previously completed details may be folded into [...]. The object still exists; only its unrelated details are hidden so you can focus on the current task.
Think About Code Organization: The Name assignment appears in this task because this is where you are adding the zoo's remaining information. The code will work here because this.ComoZoo has already been created.
However, Name and Capacity are both direct field values of the same Zoo object. Grouping related field assignments together often makes the program easier to read, debug, and maintain.
You may leave this.ComoZoo.Name = "Como Zoo"; in this section, or move it so it appears beside this.ComoZoo.Capacity = 1000;. Both placements are valid. The important ideas are that the Zoo object is created first and that related assignments are organized in a way that clearly shows the program's flow.
// Create the restrooms.
this.ComoZoo.LadiesRoom = new Restroom();
this.ComoZoo.MensRoom = new Restroom();
// Assign the remaining field value of Como Zoo.
// You may place this beside Capacity to group Zoo field values.
this.ComoZoo.Name = "Como Zoo";
// Create the ticket booth.
this.ComoZoo.TicketBooth = new Booth();Understanding the Change: The restroom and ticket booth lines create objects. The name line fills in a string value on the zoo object.
What's Different Now?: The main zoo object now has references to its restroom objects and ticket booth object. It also has a name stored directly on the zoo.
Problem: The animal object exists, but it does not yet have any details.
Solution: Fill in the fields on the existing FeaturedAnimal object. Add these lines after FeaturedAnimal has been assigned a new Animal object.
// Assign field values of the featured animal.
this.ComoZoo.FeaturedAnimal.Age = 4;
this.ComoZoo.FeaturedAnimal.Sex = "Female";
this.ComoZoo.FeaturedAnimal.IsPregnant = true;
this.ComoZoo.FeaturedAnimal.Name = "Dolly";
this.ComoZoo.FeaturedAnimal.Type = "Dingo";
this.ComoZoo.FeaturedAnimal.Weight = 35.3;Take a Closer Look: Each line starts at the window, follows the ComoZoo reference, follows the FeaturedAnimal reference, and then fills in one field on that animal.
Problem: The restroom and ticket booth objects exist, but they still need values. The ticket booth also needs an employee object before you can fill in employee information.
Solution: Fill in the restroom fields, set the ticket price, and create the attendant object. Add these lines after LadiesRoom, MensRoom, and TicketBooth have been created.
// Assign field values of the ladies' restroom.
this.ComoZoo.LadiesRoom.Capacity = 4;
this.ComoZoo.LadiesRoom.Sex = "Female";
// Assign field values of the men's restroom.
this.ComoZoo.MensRoom.Capacity = 4;
this.ComoZoo.MensRoom.Sex = "Male";
// Create and assign field values of the ticket booth.
this.ComoZoo.TicketBooth.Attendant = new Employee();
this.ComoZoo.TicketBooth.TicketPrice = 15.00m;What This Code Does: The ticket booth can store a reference to an employee. The line with new Employee() creates that employee object so the next section can fill in the attendant's name and number.
Putting It Together: The zoo now has restroom details and a ticket booth that knows its ticket price. The booth also has an attendant object ready for employee information.
Problem: The ticket booth now has an attendant object, but the attendant does not yet have values.
Solution: Fill in the fields on the existing attendant object. Add these lines after the attendant object has been created.
// Assign field values of the ticket booth attendant.
this.ComoZoo.TicketBooth.Attendant.Name = "Sam";
this.ComoZoo.TicketBooth.Attendant.Number = 42;Key Takeaway: The ticket booth attendant now has identifying information. The program can connect the ticket booth to a specific employee instead of leaving the employee object blank.
Before submitting, make sure the project runs and uses the expected object values.
StyleCop Must Be Clean: StyleCop is active for this project. Before submitting, build the solution and resolve every StyleCop warning introduced by your changes. The guided comments in this walkthrough are complete sentences and end with periods so they follow the expected comment style.
Need a Refresher?: Review these previously introduced topics if you need help:
Stop debugging, save your work, and submit according to your instructor's directions.
You created the first complete Como Zoo object graph. The final diagram shows the objects, references, and field values that should exist when the checkpoint is complete.