Food Magnate Simulation questions
You have been given the code for the Food Magnate Simulation. Using that code, answer the following questions:
N.B. this code was rewritten from the original by me during the summer so it conforms to the Python style guide. Most names have been recased from PascalCase to snake_case
-
State the name of an identifier for:
- An attribute in the
Settlementclass that is only accessible to subclasses ofSettlement.- N/A, because this is Python and all attributes are accessible by all objects (the 'consenting adults' principle). However, an attribute that is considered non-public by convention is
Settlement._x_size
- N/A, because this is Python and all attributes are accessible by all objects (the 'consenting adults' principle). However, an attribute that is considered non-public by convention is
- A subclass
LargeSettlement
- A subroutine from the
Companyclass that cannot be called from outside theCompanyclass.- Again, N/A due to the 'consenting adults' principle. However, a subroutine of
Companythat by convention is considered non-public is the static methodCompany._get_distance_between_two_outlets
- Again, N/A due to the 'consenting adults' principle. However, a subroutine of
- A string method called from the
company_indexsubroutine in theSimulationclassstr.lower
- An attribute in the
-
'10' Add an option to run the simulation for many days (>1)
-
'11' Add a new
SmallSettlementclass and an option to create a small settlement in the simulation launch menu.- Your PROGRAM SOURCE CODE for the amended
- SCREEN CAPTURE(S) showing the results of the requested change
- <script id="asciicast-lzwMKAPq7GPrsUgd2DZqMuQgJ" src="https://asciinema.org/a/lzwMKAPq7GPrsUgd2DZqMuQgJ.js" async>
- '1' This question refers to the subroutine
_process_add_households_eventand the_display_events_at_day_endsubroutine within theSimulationclass.
Modify the subroutine
_process_add_households_eventin theSimulationclass. Rename the subroutine to_process_add_remove_households_eventand all calls to it so that they use the new identifier. Instead of just adding 1-4 houses to the settlement, there should be a 30% chance that 1-4 houses will leave the settlement instead.The message displayed by the subroutine should be changed so that when houses are removed, it says removed from instead of added to.
Modify the subroutine
_display_events_at_day_endin the Simulation class. The subroutine should always call the newly modified subroutine_process_add_remove_households_event.Test the changes that you have made work:
- run the Skeleton Program
- leave the first prompt blank, to indicate a normal-sized settlement
- enter D at the next prompt for default companies
- enter 6 for 'advance to next day'
- enter 1 for 'display details of households'
- repeat this until households are removed from the settlement (and are added)