// This class was suggested during the A lecture for CSE142. The Cockroach // objects use a random object to randomly select between three different // colors. import java.awt.*; import java.util.*; public class Cockroach extends Critter { private Random r; public Cockroach() { r = new Random(); } public Action getMove(CritterInfo info) { if (info.getFront() == Neighbor.OTHER) { return Action.INFECT; } else { return Action.RIGHT; } } public Color getColor() { int which = r.nextInt(3); if (which == 0) { return Color.RED; } else if (which == 1) { return Color.WHITE; } else { // which == 2 return Color.BLUE; } } public String toString() { return "<#>"; } }