// 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). import java.awt.*; public class Food2 extends Critter { private int myCount; private static int ourCount; 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; } }