2020 - Settlement

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

Variables

Random

private static Random rnd

List of Households

protected List<Household> households

int

protected int startNoOfHouseholds, xSize, ySize

Methods

Constructor

The constructor will set 'xSize' and 'ySize' to 1000. It will set the 'startNoOfHouseholds' to 250. It will then call CreateHouseholds.

GetNumberOfHousehold

This will return the number of households using the 'Count' method.

GetXSize

This will return the xSize variable.

GetYSize

This will return the ySize variable.

GetRandomLocation

This accepts parameters for 'x' and 'y', notice they are both passed with reference.

The values of 'x' and 'y' are set to a random double which is multiplied by the 'xSize'. The value is converted to an integer.

CreateHouseholds

This contains a for loop which will iterate from '0' until 'count < startNoOfHouseholds'.

Each iteration will run the 'AddHousehold' method.

AddHousehold

This creates local variables for 'x' and 'y', it then calls 'GetRandomLocation' to set these to the location to use.

A new 'Household' is then created called temp, and the 'x' and 'y' are passed as parameters.

Finally the 'temp' Household is then added to the list of 'households'

DisplayHouseholds

This will cycle through each 'Household' in 'households' and run the 'GetDetails' method for each.

FindOutIfHouseholdEatsOut

This accepts the 'ID' of a 'Household' as a parameter called 'householdNo'. It also accepts integers for the 'x' and 'y', these are passed with reference.

This method generates a random double. The 'x' and 'y' values are set using the 'GetX' and 'GetY' methods within the 'Household' class. It then uses the 'GetChanceEatOut' method to get the chance of eating out for the selected household. The if statement then compare the random double with the chance of eating out, if it is less than 'true' will be returned, and if it is greater than or equal 'false' will be returned.