// CSE 142, Marty Stepp // // All Student critters walk N/E until they reach a particular single randomly // chosen x/y location at which they congregate for a "party". // // This example was to show the use of static fields, which allow all of // the students to share a single partyX/partyY value rather than each // Student storing his own party location. import java.util.*; // for Random public class Student extends Critter { // shared party location for all students private static int partyX = -1; private static int partyY = -1; public Student() { if (partyX < 0 && partyY < 0) { // if party location is not chosen, choose one Random randy = new Random(); partyX = randy.nextInt(60); partyY = randy.nextInt(50); } } public Direction getMove() { if (getX() == partyX && getY() == partyY) { // at the party; stay here return Direction.CENTER; } else { // go north then east until I reach the party if (getY() != partyY) { return Direction.NORTH; } else { return Direction.EAST; } } } }