Food Magnate Simulation Questions
-
State the name of an identifier for:
-
A subroutine in the
Settlement
class that returns something other than a primitive valueGetRandomLocation
-
A local variable that is used to return a Boolean
CloseCompany
-
A collection attribute in the
Company
class_Outlets
-
An instance of
Settlement
_SimulationSettlement
-
-
Explain how validation might be added to the
OpenOutlet
subroutine of theCompany
class to prevent a new outlet being created beyond the bounds of the settlement.The
OpenOutlet
subroutine could be passed the instance ofSettlement
the 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
UpOrDown
in theProcessCostOfFuelChangeEvent
subroutine of theSimulation
class.The variable
UpOrDown
determines if the price of fuel will increase or decrease; ifUpOrDown
is 0 then the price goes up and if it's 1 (or anything else) then the price goes down. -
In the
Simulation
constructor, the integer literals100000
,200
, and203
are passed to theCompany
constructor when creating the 'AQA Burgers' company. State the role of each of these integer literals.100000
, the first integer literal, is passed to theCompany
initialiser as the company's balance; how much money it has.200
, the second integer literal, is passed to theCompany
initialiser as the company's first outlet's X position, and203
, the third integer literal, is passed to theCompany
initialiser as the company's first outlet's Y position. -
Describe in full the operation of the
GetIndexOfCompany
subroutine in theSimulation
class.GetIndexOfCompany
begins by setting a sentry variable,Index
, equal to a sentry value,-1
. It then iterates through each valid index into theSimulation
object's_Companies
attribute, and compares theCompany
's name, case insensitively, to the search query (by normalising both names to lower case). If theCompany
is determined to match then the current index is returned, otherwise the loop continues.If the loop completes without finding a match, then the
Index
sentry is returned. (It's never modified, so it could just be a constant. Whatever.) -
Describe the circumstances under which the
ModifyCompany
subroutine of theSimulation
class 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
LargeSettlement
constructor 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 theLargeSettlement
constructor never results in a smaller settlement size.As the
Settlement
initialiser 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
ProcessDayEnd
subroutine works in theSimulation
class.First, an empty string
Details
is created, along withProfitLossFromOutlets
andProfitLossFromThisOutlet
, both of which are set to 0.Then, if there is more than one outlet,
DeliveryCosts
is 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,
ProfitLossFromThisOutlet
is calculated for each outlet, a message is added toDetails
, andProfitLossFromOutlets
is 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
Details
is returned. -
Describe how the program would respond to a call to the
Company
constructor 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'.