Java Design

Bin contains a collection of Outcomes which reflect the winning bets that are paid for a particular bin on a Roulette wheel. In Roulette, each spin of the wheel has a number of Outcomes. Example: A spin of 1, selects the “1” bin with the following winning Outcomes: “1”, “Red”, “Odd”, “Low”, “Column 1”, “Dozen 1-12”, “Split 1-2”, “Split 1-4”, “Street 1-2-3”, “Corner 1-2-4-5”, “Five Bet”, “Line 1-2-3-4-5-6”, “00-0-1-2-3”, “Dozen 1”, “Low” and “Column 1”. These are collected into a single Bin.

Fields

  • Set outcomes ;

    Holds the connection of individual Outcomes.

For a discussion on the type declaration used for outcome, see Deferred Binding in Java.

Constructors

In addition to the default constructor that makes an empty Bin, Java programmers may find it helpful to create a two additional constructors to initialize the collection from other collections.

  • Bin();

    Creates an empty Bin. Outcomes can be added to it later.

  • Bin(Outcome[] outcomes);

    Creates an empty Bin using the this() statement to invoke the default constructor. It then loads that collection using elements of the given array.

  • Bin(Collection outcomes);

    Creates an empty Bin using the this() statement to invoke the default constructor. It then loads that collection using an iterator over the given Collection. This relies on the fact that all classes that implement Collection will provide the iterator; the constructor can convert the elements of the input collection to a proper Set.

The array constructor will initialize the outcomes Set from an array of Outcomes. This allows the following kind of constructor call from another class.

Example 5.1. Java Bin Construction

    Outcome five= new Outcome( "00-0-1-2-3", 6 );
    Outcome[] ocZero = {
        new Outcome("0", 35 ), five }; 1
    Outcome[] ocZeroZero = {
        new Outcome("00", 35 ), five }; 2
    Bin zero= new Bin( ocZero ); 3
    Bin zerozero= bew Bin( ocZeroZero );
1

This creates ocZero, which is an array of references to two objects: the “0Outcome and the “00-0-1-2-3Outcome.

2

This creates ocZeroZero, which is an array of references to two objects: the “00Outcome and the “00-0-1-2-3Outcome.

3

This creates zero, which is the final Bin, built from ocZero, which has both “0” and “five”.

Methods

  • void add(Outcome outcome);

    Adds an Outcome to this Bin. This can be used by a builder to construct all of the bets in this Bin. Since this class is really just a façade over the underlying collection object, this method can simply delegate the real work to the underlying collection.

  • public String toString();

    An easy-to-read String output method is also very handy. This should return a String representation of the list of Outcomes in this Bin.

    For some tips on how to implement this, see Formatting in Java.