Difference between revisions of "2020 - Outlet"
(Created page with "==Variables== ===Random=== private static Random rnd ===int=== protected int visitsToday, xCoord, yCoord, capacity, maxCapacity; ===double=== protected double dailyCosts;...") |
(→AlterCapacity) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
===Constructor=== | ===Constructor=== | ||
+ | The constructor accepts parameters for 'xCoord', 'yCoord', and 'maxCapacityBase'. | ||
+ | |||
+ | It uses 'this' to access the values for 'xCoord' and 'yCoord' of the object and sets the values to those passed. In this case 'this' is used to determine if we mean the parameter called 'xCoord' or the variable called 'xCoord'. | ||
+ | |||
+ | 'capacity' is set by multipling 'maxCapacityBase' by '0.6', is 60% of 'maxCapacityBase'. | ||
+ | |||
+ | 'maxCapacity' takes the 'maxCapacityBase' and is set by adding a random number between 0 and 50, and then subtracting a random number between 0 and 50. | ||
+ | |||
+ | 'dailyCosts' are set using the following calculation: | ||
+ | dailyCosts = maxCapacityBase * 0.2 + capacity * 0.5 + 100 | ||
+ | |||
+ | Finally the 'NewDay' method is run. | ||
===GetCapacity=== | ===GetCapacity=== | ||
Line 26: | Line 38: | ||
===AlterCapacity=== | ===AlterCapacity=== | ||
+ | This method accepts a parameter for the 'change' required. | ||
+ | |||
+ | The 'oldCapacity' is stored, and then the capacity is updated by adding the 'change'. | ||
+ | |||
+ | If this causes 'capacity' to be high than 'maxCapacity', then 'capacity' is reset to the 'maxCapacity'. and the actual amount of change is returned. | ||
+ | |||
+ | The 'else if' then checks to make sure capacity is not below 0. If so 'capacity' is set to zero. | ||
+ | |||
+ | The daily costs are recalculated using the formula: | ||
+ | dailyCost = maxCapacity * 0.2 + capacity * 0.5 + 100 | ||
+ | |||
+ | Finally the value for 'change' is returned. | ||
===IncrementVisits=== | ===IncrementVisits=== | ||
Line 40: | Line 64: | ||
===GetDetails=== | ===GetDetails=== | ||
+ | This declares a new string called 'details' which is then used to concatenate several bit of information together. | ||
+ | |||
+ | This string is then returned. |
Latest revision as of 13:00, 27 January 2020
Contents
Variables
Random
private static Random rnd
int
protected int visitsToday, xCoord, yCoord, capacity, maxCapacity;
double
protected double dailyCosts;
Methods
Constructor
The constructor accepts parameters for 'xCoord', 'yCoord', and 'maxCapacityBase'.
It uses 'this' to access the values for 'xCoord' and 'yCoord' of the object and sets the values to those passed. In this case 'this' is used to determine if we mean the parameter called 'xCoord' or the variable called 'xCoord'.
'capacity' is set by multipling 'maxCapacityBase' by '0.6', is 60% of 'maxCapacityBase'.
'maxCapacity' takes the 'maxCapacityBase' and is set by adding a random number between 0 and 50, and then subtracting a random number between 0 and 50.
'dailyCosts' are set using the following calculation:
dailyCosts = maxCapacityBase * 0.2 + capacity * 0.5 + 100
Finally the 'NewDay' method is run.
GetCapacity
This will just return the capacity stored in 'capacity'.
GetX
This will just return the value of 'xCoord'.
GetY
This will just return the value of 'yCoord'.
AlterDailyCost
This accepts a parameter called 'amount' (a double), this method will just add the value of 'amount' to the 'dailyCosts' variable.
AlterCapacity
This method accepts a parameter for the 'change' required.
The 'oldCapacity' is stored, and then the capacity is updated by adding the 'change'.
If this causes 'capacity' to be high than 'maxCapacity', then 'capacity' is reset to the 'maxCapacity'. and the actual amount of change is returned.
The 'else if' then checks to make sure capacity is not below 0. If so 'capacity' is set to zero.
The daily costs are recalculated using the formula:
dailyCost = maxCapacity * 0.2 + capacity * 0.5 + 100
Finally the value for 'change' is returned.
IncrementVisits
This method will just increment the 'visitsToday' variable using 'visitsToday++'.
NewDay
This will just reset the 'visitsToday' back to 0.
CalculateDailyProfitLoss
This method will accept parameters for 'avgPricePerMeal' and 'avgCostPerMeal'. It will then return the result of this calcualtion:
(avgPricePerMeal - avgCostPerMeal) * visitsToday - dailyCosts
GetDetails
This declares a new string called 'details' which is then used to concatenate several bit of information together.
This string is then returned.