- The room starts at 77.0.
- Births and the existing temperature buttons still change the temperature.
Continue from your completed Zoo 2.4. 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.Currently the Temperature field of the BirthingRoom can be manipulated from MainWindow when it should be the BirthingRoom itself that handles the temperature and any changes.
You will make the temperature field private and give other classes public methods for reading and changing it.
BirthingRoom fields.Temperature to temperature and make it private. Initialize it to 77.0 in its declaration.InitialTemperature. The temperature field now receives its starting value directly. Keep MaxTemperature, MinTemperature, Doctor and Mother.TemperatureIncrease private readonly, rename it temperatureIncrease and keep its value 0.5.BirthingRoom.cs. Confirm this.temperature is a private double field.this.temperatureIncrease is private readonly and initialized to 0.5.this.temperature and this.temperatureIncrease. Keep the returned baby reference.BirthingRoom.BirthAnimal 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.Doctor. Confirm this.temperature increases by this.temperatureIncrease before delivery.this.temperature.this.temperature using the return type shown in the class diagram.BirthingRoom.GetTemperature() 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.77.0 for this.temperature. Confirm the returned value is 77.0.this.temperature.temperatureChange to the private temperature field.BirthingRoom.ChangeTemperature 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.temperature at 77.0 and use change 0.5. Confirm the result is 77.5.77.0 with change -0.5. Confirm the result is 76.5.Temperature field read with this.BirthArea.GetTemperature(), retaining ToString("0.0").Zoo.GetTemperatureDisplay() 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.BirthArea.GetTemperature(). For returned value 77.0, confirm ToString("0.0") produces 77.0.77.5 and confirm 77.5. The decimal separator follows the current culture.Currently the VendingMachine money balance can be manipulated outside the class through both the public MoneyBalance field and the public AddMoney method.
You will make the money field and helper method private so that other classes do not have access to them.
VendingMachine.MoneyBalance to moneyBalance, make it private and update its uses inside the class.BagSize to bagSize and FoodCapacity to foodCapacity. Make both private readonly and initialize them to 65.0 and 250.0.AddMoney from public to private. Keep the amount parameter and add it to this.moneyBalance. Keep SellFood calling this helper after successful dispensing.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(amount). Follow it into the private helper.this.moneyBalance at 0.00m with payment 0.53m. Confirm the helper changes the field to 0.53m.private and the public sale method still calls it from inside the same class.BagSize and FoodCapacity field references with bagSize and foodCapacity; retain both return paths.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 of 65.0 and this.foodCapacity of 250.0.this.FoodStock at 12.0. Confirm one bag gives 77.0 and returns true.212.0. A bag would give 277.0; confirm stock remains 212.0 and the method returns false.FoodStock with the private foodCapacity field.VendingMachine.IsFull() 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.foodCapacity of 250.0 and this.FoodStock of 12.0, confirm false.250.0 and confirm true.VendingMachine.Fill() 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 at 12.0. Trace three accepted 65-pound bags: stock becomes 77.0, 142.0 and 207.0.this.foodCapacity of 250.0. The loop stops and returns 3.207.0. Confirm no bag fits, stock stays unchanged and the return value is 0.Wallet.cs.MoneyBalance to moneyBalance, make it private and update AddMoney and RemoveMoney to use that field. Keep the existing positive-deposit and limited-withdrawal checks.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.this.moneyBalance at 2.00m and request 3.00m.2.00m is removed, the ending balance is 0.00m and the returned amount is 2.00m.this.moneyBalance using the return type shown in the class diagram.Wallet.GetMoneyBalance() 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.moneyBalance of 5.25m. Confirm the method returns 5.25m without assigning to the field.Currently the guest’s wallet can be replaced from outside the Guest class.
You will make the wallet reference private and let the guest provide public operations for using it.
Guest.cs.Guest’s own references from this.Wallet to this.wallet.private Wallet wallet = new Wallet();Guest.cs. Find private Wallet wallet = new Wallet();.this.wallet is initialized for each newly created Guest.MainWindow should deposit through Guest.AddMoney rather than replace the private wallet reference.this.wallet.AddMoney(amount).Guest.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.5.25m into an initially empty wallet. Follow amount into this.wallet.AddMoney(amount).this.moneyBalance changes from 0.00m to 5.25m.0.00m and -1.00m. Confirm the positive-amount guard rejects both without changing the balance.this.wallet.GetMoneyBalance() using the return type shown in the class diagram.Guest.GetMoneyBalance() 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.wallet.GetMoneyBalance() into Wallet. With this.moneyBalance of 5.25m, confirm Wallet returns 5.25m.Guest and confirm it returns that same amount, without depositing or withdrawing money.RemoveMoney to private and use this.wallet.RemoveMoney(amount). Keep its decimal return value.Guest.cs. Confirm RemoveMoney is declared private.Guest.FeedAnimal. Confirm the call stays inside Guest and forwards the amount to this.wallet.RemoveMoney(amount).Guest returns the actual amount removed by Wallet rather than the requested amount unconditionally.this.wallet. Replace the direct balance read with this.wallet.GetMoneyBalance().Guest.FeedAnimal 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.wallet before calling this.wallet.GetMoneyBalance().5.25m and valid first Como payment 0.53m, trace the success path and result 0.6 and no payment or feeding call.Animal.cs.MakePregnant, GetPortionSize and Reproduce.| Field | Value |
|---|---|
afterbirthPercentage |
0.1 |
babyWeightPercentage |
0.1 |
eatBabyWeightGainPercentage |
0.1 |
eatWeightGainPercentage |
0.8 |
portionSizePercentage |
0.02 |
moveWeightLossPercentage |
0.03 |
Animal.GetIsPregnant(). Confirm it checks this.baby != null.this.baby as null: expect false. Trace a non-null baby reference: expect true.GetIsPregnant() instead of reading the private baby field.weightLossAmount from this.Weight multiplied by this.moveWeightLossPercentage, then subtract it from Weight.Animal.Move() 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.Weight of 35.3 and the configured movement rate 0.03.1.059 and leaves this.Weight approximately 34.241.AddAnimal and read the population size through GetAnimalCount.The Zoo class should be the only class with direct access to the list of animals. Additionally, it is possible to add null to the list, which is not something we want to happen.
You will make the list private, refactor the code to use it and make sure an animal is not null before adding it.
Zoo.cs.new List<Animal>() in the field declaration.Zoo, including wake, weight and search methods, to use this.animals.Zoo.cs. Confirm the population list is now this.animals and is private.this.animals. Trace Como’s starting total approximately 84.6 and average approximately 28.2.this.animals and still returns the first matching reference.this.animals only if it is not null.Zoo.AddAnimal 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.animals.Add(animal) runs once and the count increases by one.animal equal to null. Confirm Add is skipped and the count stays unchanged.this.animals.Count using the return type shown in the class diagram.Zoo.GetAnimalCount() 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.animals.Count is 3 and the method returns 3.0. Confirm reading the count does not add or remove animals.this.AddAnimal(baby) instead of adding to the list directly.Zoo.BirthAnimal 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.baby into this.AddAnimal(baby). Confirm the method returns the same reference.MainWindow.xaml.cs.ComoZoo to comoZoo and SanDiegoZoo to sanDiegoZoo and make both private.ZooAnimalCount to zooAnimalCount and ZooAverageAnimalWeight to zooAverageAnimalWeight and make both private.MainWindow. Keep method names, XAML names, strings and Click handler names unchanged.Visitor.Wallet and assign its MoneyBalance. After the visitor’s name and age are set, call this.comoZoo.Visitor.AddMoney(5.25m).BagSize and FoodCapacity assignments; those values now come from its readonly declarations. Keep the price and starting FoodStock assignments.BirthArea.InitialTemperature, BirthArea.TemperatureIncrease and BirthArea.Temperature assignments. Keep the room’s doctor and other setup.this.comoZoo.AddAnimal(animal). Keep the existing animal data, array placement and display calls.MainWindow.CreateComoZoo and read its calls in order.Visitor.AddMoney(...) rather than direct wallet-field access.AddAnimal(...) rather than direct access to animals.this.comoZoo.Visitor.Wallet and assign its MoneyBalance. After the visitor’s name and age are set, call this.sanDiegoZoo.Visitor.AddMoney(3.75m).BagSize and FoodCapacity assignments; those values now come from its readonly declarations. Keep the price and starting FoodStock assignments.BirthArea.InitialTemperature, BirthArea.TemperatureIncrease and BirthArea.Temperature assignments. Keep the room’s doctor and other setup.this.sanDiegoZoo.AddAnimal(animal). Keep the existing animal data, array placement and display calls.MainWindow.CreateSanDiegoZoo and read its calls in order.Visitor.AddMoney(...) rather than direct wallet-field access.AddAnimal(...) rather than direct access to animals.this.sanDiegoZoo.this.sanDiegoZoo.BirthArea.ChangeTemperature(temperatureChange).MainWindow’s temperature helper. Confirm the supplied positive or negative change is passed to zoo.BirthArea.ChangeTemperature(...).0.5 from starting temperature 77.0: expect 77.5. Trace -0.5 from a separate starting 77.0: expect 76.5.MainWindow no longer assigns the private temperature field directly.Animals.Count reads with the corresponding zoo.GetAnimalCount() call.ChangeSanDiegoTemperature. Read the displayed value through BirthArea.GetTemperature().newSanDiegoZooButton_Click, read the initial display through BirthArea.GetTemperature(). Keep ToString("0.0") on each displayed temperature.| Handler | Replacement statement |
|---|---|
getComoZooAnimalCount_Click |
this.zooAnimalCount = this.comoZoo.GetAnimalCount(); |
getSanDiegoZooAnimalCount_Click |
this.zooAnimalCount = this.sanDiegoZoo.GetAnimalCount(); |
Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.3 and San Diego 2. Confirm one occupied map space in each.VendingMachine.Fill(). Recreate Como and fill once without feeding first. Inspect this.FoodStock as 207.0.this.FoodStock as 212.0.F5 to continue. Stop debugging and remove the breakpoint before the next check.New San Diego Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.77.0. Click increase then decrease: confirm 77.5 then 77.0.CreateComoZoo, temporarily try this.comoZoo.animals.Add(animal). Build and observe the private-access error, then remove that test line.this.comoZoo.AnimalSnackMachine.AddMoney(3000.00m). Build and observe the private-method access error, then remove that test line.Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.Guest.FeedAnimal and click Darla, feed dingo. Add the expressions in the table before stepping.| Expression | Expected state |
|---|---|
this.wallet |
Existing Wallet reference |
this.wallet.moneyBalance |
5.25 before payment |
foodCost |
0.53 |
this.moneyBalance |
Unavailable; that field belongs to Wallet |
| amount | Unavailable here; it is a parameter of later wallet methods |
Wallet.GetMoneyBalance. this now refers to Wallet, where this.moneyBalance is 5.25. Return to the funds check.Guest.RemoveMoney into Wallet.RemoveMoney. amount is 0.53; after subtraction the private balance is 4.72.VendingMachine.AddMoney runs, this refers to the machine and amount is 0.53. After addition its private moneyBalance is 0.53. Press F5 to continue.this.wallet.GetMoneyBalance() supplies the guest’s balance without exposing the wallet to MainWindow.AddAnimal(animal) call in CreateComoZoo and click New Como Zoo.| Expression | In MainWindow before the call |
|---|---|
animal.Name |
"Dolly" |
this.comoZoo.animals |
Empty list; the debugger can inspect private members |
this.animals |
Unavailable until inside Zoo.AddAnimal |
Zoo.AddAnimal. The parameter animal becomes available in Zoo; observe this.animals.Count become 1 after Add executes.Zoo.AddAnimal(null) 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.false.this.animals.Add(...) is skipped and the existing count stays unchanged.Zoo.WakeAllAnimals().New Como Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.this.animals[0].Weight, this.animals[1].Weight and this.animals[2].Weight as approximately 34.241, 32.786 and 15.035.F5 to continue. Stop debugging and remove the breakpoint before the next check.New Como Zoo to reset that zoo. Do not feed, refill, move or give birth before this test.4 and the displayed area count is 2.4.MainWindow, whose fields are now private, and retained where public fields remain.Build > Build Solution. Open View > Error List and resolve any errors introduced by this task.