/** Illustrates enumerations. */ public class Colors { /** A Color type */ public enum Color {Red, Green, Blue}; /** Construct a Color object */ public Colors(Color c) { myColor = c; } /** Returns the object's color */ public Color getColor() { return myColor; } /** Sets the object's color. @param c The color to save */ public void setColor(Color c) { myColor = c; } /** Changes the object color to the next in the enumeration sequence. */ public void rotateColor() { switch (myColor) { case Red: myColor = Color.Green; break; case Green: myColor = Color.Blue; break; case Blue: myColor = Color.Red; break; } } /** Changes the object's color to the previous in the enumeration sequence. */ public void rotateBackColor() { myColor = Color.values()[(myColor.ordinal() -1+3) % 3]; } /** Holds the object's color */ private Color myColor; }