Java Reference
In-Depth Information
LISTING 7.11
continued
//-----------------------------------------------------------------
// Constructor: Sets up each value with an associated string.
//-----------------------------------------------------------------
Season (String months)
{
span = months;
}
//-----------------------------------------------------------------
// Returns the span message for this value.
//-----------------------------------------------------------------
public String getSpan()
{
return span;
}
}
The main method of the SeasonTester class, shown in Listing 7.12, prints each
value of the Season enumerated type, as well as the span statement for each. Every
enumerated type contains a static method called values that returns a list of all
possible values for that type. This list is an iterator, so we can use the enhanced
version of a for loop to process each value.
LISTING 7.12
//********************************************************************
// SeasonTester.java Author: Lewis/Loftus
//
// Demonstrates the use of a full enumerated type.
//********************************************************************
public class SeasonTester
{
//-----------------------------------------------------------------
// Iterates through the values of the Season enumerated type.
//-----------------------------------------------------------------
public static void main (String[] args)
{
Search WWH ::




Custom Search