2020 - Household

From TRCCompSci - AQA Computer Science
Revision as of 08:58, 27 January 2020 by Admin (talk | contribs) (Created page with "==Variables== ===Random=== private Random rnd ===Double=== protected double chanceEatOutPerDay ===Int=== protected int xCoord, yCoord, ID protected static int nextID = 1...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Variables

Random

private Random rnd

Double

protected double chanceEatOutPerDay

Int

protected int xCoord, yCoord, ID
protected static int nextID = 1

Methods

Constructor

Accepts the X & Y parameters, and stores them as 'xCoord' and 'yCoord'. It generates a new random double and sets this to the 'chanceEatOutPerDay'. It sets the 'ID' to the current value of 'nextID'. It then increments 'nextID'.

GetDetails

Creates a string to concatenate the details of this household. The created string is then returned.

GetChanceEatOut

Just returns the 'chanceEatOutPerDay'.

GetX

Just returns the 'xCoord'.

GetY

Just returns the 'yCoord'.

Interesting

The 'nextID' is a static int, this means you don't need to create an object of 'Household' to use it. In this case the 'nextID' is static so that each 'Household' created will have different 'ID' values. It essentially increments after each 'Household' is created.

Having the 'rnd' private means that it is only available to this class and not any subclasses created from it.

Having the protected variables means these are private to just this class, but will also be available in any subclasses created from 'Household'.