Food Magnate Simulation Questions
-
State the name of an identifier for:
-
A subroutine in the
Settlementclass that returns something other than a primitive valueGetRandomLocation -
A local variable that is used to return a Boolean
CloseCompany -
A collection attribute in the
Companyclass_Outlets -
An instance of
Settlement_SimulationSettlement
-
-
Explain how validation might be added to the
OpenOutletsubroutine of theCompanyclass to prevent a new outlet being created beyond the bounds of the settlement.The
OpenOutletsubroutine could be passed the instance ofSettlementthe company resides within and ensure that the target X and Y are within theSettlement's X and Y bounds. -
Explain the role of the variable
UpOrDownin theProcessCostOfFuelChangeEventsubroutine of theSimulationclass.The variable
UpOrDowndetermines if the price of fuel will increase or decrease; ifUpOrDownis 0 then the price goes up and if it's 1 (or anything else) then the price goes down. -
In the
Simulationconstructor, the integer literals100000,200, and203are passed to theCompanyconstructor when creating the 'AQA Burgers' company. State the role of each of these integer literals.100000, the first integer literal, is passed to theCompanyinitialiser as the company's balance; how much money it has.200, the second integer literal, is passed to theCompanyinitialiser as the company's first outlet's X position, and203, the third integer literal, is passed to theCompanyinitialiser as the company's first outlet's Y position. -
Describe in full the operation of the
GetIndexOfCompanysubroutine in theSimulationclass.GetIndexOfCompanybegins by setting a sentry variable,Index, equal to a sentry value,-1. It then iterates through each valid index into theSimulationobject's_Companiesattribute, and compares theCompany's name, case insensitively, to the search query (by normalising both names to lower case). If theCompanyis determined to match then the current index is returned, otherwise the loop continues.If the loop completes without finding a match, then the
Indexsentry is returned. (It's never modified, so it could just be a constant. Whatever.) -
Describe the circumstances under which the
ModifyCompanysubroutine of theSimulationclass would output the text 'Invalid coordinates'.Any of the following:
- Desired X is less than 0
- Desired X is more than the X size of the settlement's
- Desired Y is less than 0
- Desired Y is more than the Y size of the settlement's
-
Currently, a call to the
LargeSettlementconstructor could not result in a settlement that is smaller than 1,000 by 1,000. This is true even if negative numbers are entered by the user when prompted for additional x and y values. Explain how a call to theLargeSettlementconstructor never results in a smaller settlement size.As the
Settlementinitialiser is called, the initial 250 houses will be within the 1000x1000 area, even if the bounds of the settlement (or even the number of houses) are lowered afterwards byLargeSettlement's initialiser. -
Describe exactly how the
ProcessDayEndsubroutine works in theSimulationclass.First, an empty string
Detailsis created, along withProfitLossFromOutletsandProfitLossFromThisOutlet, both of which are set to 0.Then, if there is more than one outlet,
DeliveryCostsis set to the base delivery cost + a calculated cost between outlets, otherwise it is set to the base delivery cost.Then, some information about the costs for the day are added to
Details.After that,
ProfitLossFromThisOutletis calculated for each outlet, a message is added toDetails, andProfitLossFromOutletsis increased byProfitLossFromThisOutlet.Next, the company's current balance is appended to
Details, updated with the daily costs, delivery costs, and profit/loss from all outlets, and the new balance is appended toDetails.Finally, the fully constructed
Detailsis returned. -
Describe how the program would respond to a call to the
Companyconstructor using a category that is neither 'fast food', 'family', nor 'named chef'.Any category other than 'fast food' or 'family' is treated as if it were a 'named chef' category; the initial values (other than category itself) are created as if the category were 'named chef'.