2020 - Brexit will half the probabilities of households eating out
Adding new function into Household class
In the household class find the following:
public double GetChanceEatOut()
{
return chanceEatOutPerDay;
}
This returns the chance of eating out per day, we are going to create a method to change the value instead. So below this enter:
public void ChangeChanceEatOut(double change)
{
chanceEatOutPerDay *= change;
}
Adding new function into Settlement class
The 'households' list is currently protected and therefore not available outside of the class. You could just change 'protected' to 'public', however it will be better to create a new method to access it instead. So add the following into the 'Settlement' class:
public List<Household> Households()
{
return households;
}
Adding new event processing method in Simulation class
add the following method into the simulation class to process brexit:
private bool brexit = false;
private void ProcessBrexit()
{
if (!brexit)
{
foreach (Household h in simulationSettlement.Households())
{
h.ChangeChanceEatOut(0.2);
}
Console.WriteLine("Brexit has reduced how often households will eat out.");
brexit = true;
}
}
This will cycle through each household and change the chance of eating out. It will only do this once because the bool starts as false and is then changed to true to record that brexit has happen.
Now to decide when brexit happens, look for the 'DisplayEventsAtDayEnd' method. You should have:
private void DisplayEventsAtDayEnd()
{
Console.WriteLine("\n***********************");
Console.WriteLine("***** Events: *****");
Console.WriteLine("***********************\n");
double eventRanNo;
eventRanNo = rnd.NextDouble();
if (eventRanNo < 0.25)
{
eventRanNo = rnd.NextDouble();
if (eventRanNo < 0.25)
{
ProcessAddHouseholdsEvent();
}
eventRanNo = rnd.NextDouble();
if (eventRanNo < 0.5)
{
ProcessCostOfFuelChangeEvent();
}
eventRanNo = rnd.NextDouble();
if (eventRanNo < 0.5)
{
ProcessReputationChangeEvent();
}
eventRanNo = rnd.NextDouble();
if (eventRanNo >= 0.5)
{
ProcessCostChangeEvent();
}
}
else
{
Console.WriteLine("No events.");
}
}
The outer if statement essentially gives a 25% chance of an event happening. The the inner if statements decide if each event happens, each one is essentially 50-50. So copy the 'eventRanNo' and one of the inner if statements, paste it underneath and edit it to run the 'ProcessBrexit' method:
eventRanNo = rnd.NextDouble();
if (eventRanNo < 0.1)
{
ProcessBrexit();
}