Difference between revisions of "2020 - Display how many days have passed"
(Created page with "=The Issue= The simulation doesn't record the number of days passed. =The Solution= Create a variable in the simulation class called 'days'. Increment 'days' every time the s...") |
(→Example) |
||
Line 29: | Line 29: | ||
DisplayEventsAtDayEnd(); | DisplayEventsAtDayEnd(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
Before these two lines add: | Before these two lines add: | ||
Line 35: | Line 36: | ||
days++; | days++; | ||
Console.WriteLine("Days Passed: " + days); | Console.WriteLine("Days Passed: " + days); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | You could also write this in the main menu, find the 'DisplayMenu' method in the simulation class: | ||
+ | |||
+ | <syntaxhighlight lang=csharp | ||
+ | public void DisplayMenu() | ||
+ | { | ||
+ | Console.WriteLine("\n*********************************"); | ||
+ | Console.WriteLine("********** MENU **********"); | ||
+ | Console.WriteLine("*********************************"); | ||
+ | Console.WriteLine("1. Display details of households"); | ||
+ | Console.WriteLine("2. Display details of companies"); | ||
+ | Console.WriteLine("3. Modify company"); | ||
+ | Console.WriteLine("4. Add new company"); | ||
+ | Console.WriteLine("6. Advance to next day"); | ||
+ | Console.WriteLine("Q. Quit"); | ||
+ | Console.Write("\n Enter your choice: "); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Edit it to also do these 'Console.WriteLine' commands first: | ||
+ | |||
+ | <syntaxhighlight lang=csharp> | ||
+ | Console.WriteLine("\n*********************************"); | ||
+ | Console.WriteLine("Days Passed: " + days); | ||
+ | Console.WriteLine("\n*********************************"); | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 16:53, 10 December 2019
The Issue
The simulation doesn't record the number of days passed.
The Solution
Create a variable in the simulation class called 'days'. Increment 'days' every time the simulation processes a day. Final display the value on the main menu.
Example
find the simulation class, look for this:
class Simulation
{
private static Random rnd = new Random();
protected Settlement simulationSettlement;
protected int noOfCompanies;
protected double fuelCostPerUnit, baseCostForDelivery;
protected List<Company> companies = new List<Company>();
Now add a new variable:
public int days=0;
Now find the 'ProcessDayEnd' method in the simulation class. In the method you will see the final two lines of code is:
DisplayCompaniesAtDayEnd();
DisplayEventsAtDayEnd();
Before these two lines add:
days++;
Console.WriteLine("Days Passed: " + days);
You could also write this in the main menu, find the 'DisplayMenu' method in the simulation class:
Edit it to also do these 'Console.WriteLine' commands first:
<syntaxhighlight lang=csharp>
Console.WriteLine("\n*********************************");
Console.WriteLine("Days Passed: " + days);
Console.WriteLine("\n*********************************");