// Variation of the standard Food class that keeps track of how many critters // of its kind have been constructed and what it's place is in that sequence. // It uses this information to have a custom toString that displays text like // "7 of 9" (indicating that it is critter #7 in a sequence of 9 Food2 critters // that have been constructed). // // It provides an example of a use of a static field shared by all critters of // this type (ourCount) versus a field where each critter has its own version // of that field (myCount). If you use static fields for the tournament, you // need to include a static method called initStatic that sets all of your // static fields to appropriate starting values. This method is called once // before the beginning of each simulation. import java.awt.*; public class Food2 extends Critter { private int myCount; private static int ourCount; // called before a new simulation starts up public static void initStatic() { ourCount = 0; } public Food2() { ourCount++; myCount = ourCount; } public Action getMove(CritterInfo info) { return Action.INFECT; } public Color getColor() { return Color.GREEN; } public String toString() { return myCount + " of " + ourCount; } }