//: enumerated/cartoons/EnumImplementation.java // An enum can implement an interface package enumerated.cartoons; import java.util.*; import net.mindview.util.*; enum CartoonCharacter implements Generator { SLAPPY, SPANKY, PUNCHY, SILLY, BOUNCY, NUTTY, BOB; private Random rand = new Random(47); public CartoonCharacter next() { return values()[rand.nextInt(values().length)]; } } public class EnumImplementation { public static void printNext(Generator rg) { System.out.print(rg.next() + ", "); } public static void main(String[] args) { // Choose any instance: CartoonCharacter cc = CartoonCharacter.BOB; for(int i = 0; i < 10; i++) printNext(cc); } } /* Output: BOB, PUNCHY, BOB, SPANKY, NUTTY, PUNCHY, SLAPPY, NUTTY, NUTTY, SLAPPY, *///:~