2020 - Display how many days have passed

From TRCCompSci - AQA Computer Science
Revision as of 15:50, 10 December 2019 by Admin (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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);