- Creation calls pass the existing scenario values as arguments.
- Constructors assign the starting state and connect contained objects.
Continue from your completed Zoo 2.5. Use the diagrams and the directions below to make the next set of changes.
Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.3 and San Diego 2.77.0.Currently MainWindow instantiates employees and assigns their field values, when it should be the responsibility of the class to handle assigning those values.
You will instantiate Employee by passing values into a constructor that assigns the required fields.
Employee.cs based on the class and activity diagrams.Name and Number to private fields named name and number.Employee(string name, int number) and assign both parameters to their corresponding fields.Employee.Employee 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.name of Sam and number of 42.this.name becomes Sam and this.number becomes 42.Booth.cs based on the class and activity diagrams.TicketPrice private and rename it ticketPrice. Keep Attendant public for now.Booth(Employee attendant, decimal ticketPrice), assign this.Attendant from attendant and assign this.ticketPrice from ticketPrice.Booth.Booth 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.Employee reference and ticket price 15.00m.this.Attendant receives Sam’s reference and this.ticketPrice receives 15.00m. No second Employee is created.Guest.cs based on the class and activity diagrams.Name and Age private fields named name and age. Remove new Wallet() from the wallet field declaration, leaving the private field.Guest(string name, int age, decimal moneyBalance). Assign name and age, instantiate this.wallet, then call this.AddMoney(moneyBalance).Guest.Guest 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.Darla, 11 and 5.25m as the constructor arguments.this.name is Darla, this.age is 11 and the private wallet exists. Follow AddMoney: the wallet ends with moneyBalance of 5.25m.MainWindow is handling the instantiation of the animal snack machine and assigning its values, when the class should handle its required starting information.
You will instantiate VendingMachine by passing values into a constructor that assigns the required fields.
VendingMachine.cs based on the class and activity diagrams.FoodPricePerPound private readonly as foodPricePerPound; make FoodStock private as foodStock. Update the class’s own references to those fields.VendingMachine(decimal foodPrice). Assign foodPricePerPound from the parameter and call Fill so the existing loop supplies the initial stock.VendingMachine.VendingMachine 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.0.75m. Confirm this.foodPricePerPound receives 0.75m.this.Fill() from empty stock. Three 65-pound bags give this.foodStock of 195.0; another bag would exceed 250.0. Confirm this.moneyBalance stays 0.00m.BirthingRoom.cs based on the class and activity diagrams.= 77.0 from the temperature field declaration. Add private readonly double initialTemperature = 77.0;BirthingRoom(Employee doctor). Assign temperature from initialTemperature, set MaxTemperature to 85.0 and MinTemperature to 55.0, then assign Doctor from the existing doctor parameter.BirthingRoom.BirthingRoom 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.Employee reference. Confirm this.Doctor receives that reference.this.temperature is 77.0, this.MaxTemperature is 85.0 and this.MinTemperature is 55.0.Restroom.cs based on the class and activity diagrams.Restroom(int capacity, string sex) and assign the fields from the parameters.Restroom.Restroom 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.4 and sex Female.this.capacity and this.sex. Confirm this.capacity is 4 and this.sex is Female. Readonly initialization occurs inside the constructor.MainWindow is handling the instantiation of the animals and assigning their values, when the Animal class should handle assigning those values.
You will instantiate Animal by passing values into a constructor that assigns the required fields.
Animal.cs based on the class and activity diagrams.Animal(string type, string sex, string name, int age, double weight). Assign Type, sex, Name, age and Weight from the corresponding parameters.Animal.Animal 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.Dingo, sex Female, name Dolly, age 4 and weight 35.3.this.Type, this.sex, this.Name, this.age and this.Weight receive those respective values. Confirm this.baby remains null until MakePregnant runs.Food is instantiated in different places for different reasons, and its required weight should be assigned in Food itself.
You will instantiate Food by passing values into a constructor that assigns the required fields.
Food.cs based on the class and activity diagrams.Food(double weight).Weight field from the weight parameter.Food.Food 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.1.25.this.Weight to 1.25 before the new Food reference is returned to its caller.this.foodPricePerPound using the return type shown in the class diagram.VendingMachine.GetFoodPricePerPound() 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.foodPricePerPound of 0.75m. Follow the return statement: confirm the returned value is 0.75m.this.foodPricePerPound.this.foodStock using the return type shown in the class diagram.VendingMachine.GetFoodStock() 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.foodStock of 195.0. Follow the return statement: confirm the returned value is 195.0.this.foodStock.machine.FoodPricePerPound read with machine.GetFoodPricePerPound().machine.FoodStock read with machine.GetFoodStock(). Keep the wallet, payment, stock, refund and result-code logic.Guest.FeedAnimal. Find both food-price reads, including the price-validity guard.GetFoodPricePerPound() rather than reading the old public FoodPricePerPound field.0.00m and confirm the invalid-price result occurs before division or payment. Trace valid Como price 0.75m and confirm the purchase path can continue.this.sex using the return type shown in the class diagram.Animal.GetSex() 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.sex of "Female". Follow the return statement: confirm the returned value is "Female".this.sex.this.baby using the Animal constructor: the case’s type, "Male", string.Empty, age 0 and this.Weight multiplied by this.babyWeightPercentage.Weight assignments; those values now come from the constructor.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.35.3, confirm the baby constructor receives weight approximately 3.53.Name is string.Empty.baby.Name and confirm it supplies Baby after delivery.Food’s constructor at the existing food-creation point.new Food() followed by a Weight assignment with new Food(amount), assigned to foodPacket. Keep the amount/stock guard and stock subtraction.VendingMachine.RemoveFood 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.foodStock. Confirm the success branch constructs a Food with that amount and reduces stock.this.foodStock. Confirm the branch returns null without constructing Food or reducing stock.Zoo creates its own list, snack machine, birthing room and restrooms.Zoo without duplicating them.MainWindow is handling the instantiation of the zoo, its snack machine, birth area and restrooms, and assigning their values.
You will move the zoo-owned setup into the Zoo constructor.
Zoo.cs.new List<Animal>() from the private readonly animals field declaration. Make Capacity, LadiesRoom, MensRoom and Name private with lowercase names.TicketBooth and Visitor from the parameters.AnimalSnackMachine using animalFoodPrice, BirthArea using doctor, and the two restrooms using restroomCapacity and the corresponding "Female" or "Male" string.Zoo.Zoo 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.BirthingRoom constructor.Booth, Employee or Guest objects.new VendingMachine(...) and new BirthingRoom(...) calls. Confirm each owned service is created once.this.name using the return type shown in the class diagram.Zoo.GetName() 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.name of "Como Zoo". Follow the return statement: confirm the returned value is "Como Zoo".this.name.Animal creation, with the corresponding employee, booth, visitor and Zoo constructor calls. Use the example and table below.BirthArea.Mother assignment, and all pen/tank array setup and display calls.Animal creation and its following field assignments with the Animal constructor call from the animal table. Declare animal once and reuse it for later animals.Employee attendant = new Employee("Sam", 42);
Booth booth = new Booth(attendant, 15.00m);
Employee doctor = new Employee("Flora", 98);
Guest visitor = new Guest("Darla", 11, 5.25m);
this.comoZoo = new Zoo("Como Zoo", 1000, 4, 0.75m, booth, doctor, visitor);| type | sex | name | age | weight | Call MakePregnant |
|---|---|---|---|---|---|
| Dingo | Female | Dolly | 4 | 35.3 | Yes |
| Dingo | Female | Dixie | 3 | 33.8 | Yes |
| Platypus | Female | Pammy | 2 | 15.5 | Yes |
Animal animal = new Animal("Dingo", "Female", "Dolly", 4, 35.3);MainWindow.CreateComoZoo and compare each new call with that class’s constructor signature.this.comoZoo.Animal creation, with the corresponding employee, booth, visitor and Zoo constructor calls. Use the example and table below.BirthArea.Mother assignment, and all pen/tank array setup and display calls.Animal creation and its following field assignments with the Animal constructor call from the animal table. Declare animal once and reuse it for later animals.Use the same local variable declarations as the Como example, with these San Diego values. Each Employee, Booth and Guest entry below describes a constructor call; include new when creating that object.
| Object / parameter | Value |
|---|---|
| attendant | Employee("Betty", 84) |
| booth | Booth(attendant, 25.50m) |
| doctor | Employee("Steve", 24) |
| visitor | Guest("Dave", 13, 3.75m) |
Zoo name |
"San Diego Zoo" |
Zoo capacity |
3000 |
restroomCapacity |
12 |
animalFoodPrice |
1.20m |
| type | sex | name | age | weight | Call MakePregnant |
|---|---|---|---|---|---|
| Platypus | Female | Patti | 5 | 3.27 | Yes |
| Hummingbird | Male | Harold | 1 | 0.5 | No |
MainWindow.CreateSanDiegoZoo and compare each new call with that class’s constructor signature.this.sanDiegoZoo.zoo.Name with zoo.GetName(). Keep the search, transaction and result-code switch unchanged.Zoo.GetName(). Confirm it returns this.name.MainWindow name read. Confirm it calls zoo.GetName() rather than accessing the private name field.Como Zoo and San Diego result San Diego Zoo into their respective messages.zoo.Name read with zoo.GetName(). Keep the creation-method calls and area-count messages.baby.Sex with baby.GetSex(). Keep the birth guards, array placement, names, messages and temperature refresh.| Handler | Read expression |
|---|---|
newComoZooButton_Click |
this.comoZoo.GetName() |
newSanDiegoZooButton_Click |
this.sanDiegoZoo.GetName() |
birthDingoButton_Click |
baby.GetSex() |
birthPlatypusButton_Click |
baby.GetSex() |
Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.3 and 2 and one starting map occupant per zoo.77.0, then increase once for 77.5 and decrease once for 77.0.New Como Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.4 and the newborn in this.comoZoo.Pen.PenSpaces[0].Employee creation in CreateComoZoo, then click New Como Zoo.| Expression | Expected state |
|---|---|
this.comoZoo |
null on this first creation |
| attendant | Not assigned yet; null or unavailable |
| name | Unavailable in MainWindow; constructor parameter |
| number | Unavailable in MainWindow; constructor parameter |
Employee and F10 for assignments.Employee’s constructor body, name is "Sam" and number is 42. this refers to the new Employee. Its name field is initially null and number field is initially 0.MainWindow. attendant now refers to that Employee.Booth’s constructor and confirm its Attendant is the same reference. Press F5 to continue and remove these breakpoints.name and field this.name before the assignment.F10 over this.name = name;. Confirm the field now holds the parameter’s value.name is the supplied argument; this.name is the field stored by this Employee object.F5 to continue. Stop debugging and remove the breakpoint before the next check.Zoo constructor’s first statement and click New Como Zoo. Use F11 to follow its contained-object construction.| Expression | Expected state at the first statement |
|---|---|
| name | "Como Zoo" |
animalFoodPrice |
0.75m |
| doctor | Flora’s existing Employee reference |
| visitor | Darla’s existing Guest reference |
this.animals |
null before the list assignment |
this.AnimalSnackMachine |
null before machine creation |
this.BirthArea |
null before room creation |
this.ladiesRoom |
null before restroom creation |
this.mensRoom |
null before restroom creation |
VendingMachine and observe foodPrice become 0.75m. Follow Fill: foodStock starts at 0 and becomes 65, 130 and 195; the next whole bag is rejected by the existing fit check.Zoo and enter BirthingRoom. Its initialTemperature is 77.0, temperature starts at 0 before its body assignment, and Doctor is assigned the same doctor parameter.Zoo, expand this.ladiesRoom and this.mensRoom. Confirm their private capacity values are 4 and their sex values are "Female" and "Male". Press F5 to continue and remove these breakpoints.foodStock as 195.0.new VendingMachine(...) into Fill(). Confirm constructor-driven filling produced that stock.MainWindow no longer supplies the old initial FoodStock assignment.F5 to continue. Stop debugging and remove the breakpoint before the next check.foodPacket = new Food(amount); in VendingMachine.RemoveFood, then click Darla, feed dingo.| Expression | Expected state |
|---|---|
| amount | Approximately 0.7066667 |
foodPacket |
null before the assignment |
| weight | Unavailable in this method; Food constructor parameter |
this.foodStock |
Already reduced by amount; subtraction precedes Food creation |
Food and F10 through its assignment.Food, weight is approximately 0.7066667 and this.Weight starts at 0. After the assignment it holds the supplied weight.RemoveFood and the existing sale/feeding path. Press F5 to continue, then remove the breakpoint.Food constructor breakpoint, compare parameter weight with this.Weight before and after the assignment.Food reference already has its required weight.F5 to continue. Stop debugging and remove the breakpoint before the next check.