public class Model { private int numberOfAgents = 3; private int numberOfIterations = 10; // Label to refer to our agents. // Note that we use the interface so we don't have to worry about the subclass. private Agent[] agents = new Agent[numberOfAgents]; private Environment world = new Environment(); public Model() { // Code to set up the agents. // Note that because "agents" is set up as an array of type Agent[], we could // actually add more than one agent type to the array -- everything added is // treated as a generic Agent. for (int i = 0; i < agents.length; i++) { agents[i] = new Nibbler(world); } // Code to set the default Environment values. for (int i = 0; i < world.getHeight(); i++) { for (int j = 0; j < world.getWidth(); j++) { world.setDataValue(j, i, 255.0); } } // Code to run the model. // Again, note that we don't need to worry about the types of agents. // Whatever the type of agent, they will all have a run() method, as it // is defined in the Agent Interface, and our array is of type Agent. for (int i = 0; i < numberOfIterations; i++) { for (int j = 0; j < numberOfAgents; j++) { agents[j].run(); System.out.println("value at " + agents[j].getX() + " " + agents[j].getY() + " is " + world.getDataValue(agents[j].getX(),agents[j].getY())); } } } public static void main (String args[]) { new Model(); } }