public class Boxes implements Color { public static void main(String[] args) { Box[] b = { new Box(randColor()), new Box(randColor()), new Box(randColor()) }; Box target = new Box(Color.BLUE); System.out.println(target); boolean found = false; for (int i=0 ; i < b.length ; i++) { System.out.println("Box "+i+": "+b[i]); if (target.equals(b[i])) found = true; } System.out.println("Blue box found? " + found); } public static int randColor() { return MyMath.randInt(Color.BLUE,Color.YELLOW); } } class Box implements Color { private int color = Color.BLUE; public Box(int color) { this.color=color; } public int getColor() { return color; } public boolean equals(Object other) { return color==((Box)other).color; } public String toString() { switch (color) { case Color.BLUE: return "Blue"; case Color.RED: return "Red"; case Color.YELLOW: return "YELLOW"; default: return "UNKNOWN"; } } } interface Color { public final int BLUE = 0; public final int RED = BLUE+1; public final int YELLOW = RED+1; } class MyMath { public static int randInt(int low, int high) { return (int) (Math.random()*(high-low+1)) + (int)low; } }