// Class: Simulation
//
// This is a slightly modified version of the College Board's Simulation
// class, as allowed by the GNU General Public License.  Simulation is a
// core class within the AP(r) CS Marine Biology Simulation
// case study (see www.collegeboard.com/ap/students/compsci).
//
// The only modification made for this version was to make it extend the
// EnvAppController class.
//
// The original copyright and license information for Simulation is:
//
// AP(r) Computer Science Marine Biology Simulation:
// The Simulation class is copyright(c) 2002 College Entrance
// Examination Board (www.collegeboard.com).
//
// This class is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation.
//
// This class is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

/**
 *  AP® Computer Science Marine Biology Simulation:
* A Simulation object controls a simulation of fish * movement in an Environment. * *

* The Simulation class is * copyright© 2002 College Entrance Examination Board * (www.collegeboard.com). * It has been modified, as allowed by the GNU General Public License, * to extend the EnvAppController class. * * @author Alyce Brady * @version 1 January 2003 * @see Environment * @see EnvDisplay * @see Fish **/ public class Simulation extends EnvAppController { // Instance Variables: Encapsulated data for each simulation object private Environment theEnv; private EnvDisplay theDisplay; /** Constructs a Simulation object for a particular * environment. * @param env the environment on which the simulation will run * @param display an object that knows how to display the environment **/ public Simulation(Environment env, EnvDisplay display) { theEnv = env; theDisplay = display; // Display the initial state of the simulation. theDisplay.showEnv(); Debug.println("-------- Initial Configuration --------"); Debug.println(theEnv.toString()); Debug.println("---------------------------------------"); } /** Runs through a single step of this simulation. **/ public void step() { // Get all the fish in the environment and ask each // one to perform the actions it does in a timestep. Locatable[] theFishes = theEnv.allObjects(); for ( int index = 0; index < theFishes.length; index++ ) { ((Minnow)theFishes[index]).act(); } // Display the state of the simulation after this timestep. theDisplay.showEnv(); Debug.println(theEnv.toString()); Debug.println("-------- End of Timestep --------"); } }