Design

Wheel contains the 38 individual bins on a Roulette wheel, plus a random number generator. It can select a Bin at random, simulating a spin of the Roulette wheel.

For those new to Java, see Java Subclass Constructors.

For those new to Python, see Python Subclass Constructors.

Fields

  • Java: java.util.Vector bins = new Vector( 38 );

    Python: bins = 38*[None] 

    Contains the individual Bin instances.

  • Java: java.util.Random rng = new java.util.Random();

    Python: rng = random.Random() 

    Generates the next random number, used to select a Bin from the bins collection.

Constructors

  • Wheel();

    Creates a new wheel with 38 empty Bins. It will also create a new random number generator instance.

    At the present time, this does not do the full initialization of the Bins. We'll rework this in a future exercise.

Methods

  • addOutcome(int number,
               Outcome outcome);

    Adds the given Outcome to the Bin with the given number.

  • next();

    Generates a random number between 0 and 37, and returns the randomly selected Bin.

    Java: Be sure to note that the java.util.Random nextInt method uses the size of the bins collection to return values from 0 to the size of the collection. Typically there are 38 values, numbered from 0 to 37.

    Python: the choice function of the random module will select one of the available Bins from the bins list.

    In later chapters, we'll revisit ways to test this method. For now, it returns a random result that's difficult to unit test.

  • Bin getBin(int aBin);

    Returns the given Bin from the internal collection.