/** Chapter 2, Exercise Set 2, Question 1 * Write a simple driver program that constructs a BoundedEnv * environment and then tests answers to Analysis Question Set 3. **/ public class Ch2ExSet2Q1 { // Specify number of rows and columns in environment. private static final int ENV_ROWS = 20; // rows in environment private static final int ENV_COLS = 20; // columns in environment /** Start the Marine Biology Simulation program. * The String arguments (args) are not used in this application. **/ public static void main(String[] args) { // Construct an empty environment and several fish in the context // of that environment. BoundedEnv env = new BoundedEnv(ENV_ROWS, ENV_COLS); // Set up the information given in Analysis Question Set 3 Location loc1 = new Location(7, 3); Location loc2 = new Location(2, 6); Location loc3 = new Location(4, 8); Fish f1 = new Fish(env, loc1); Fish f2 = new Fish(env, loc2); // Question 1 System.out.println("number of objects: " + env.numObjects()); // Question 2 System.out.println("Objects in the environment are: "); Locatable[] fishList = env.allObjects(); for ( int index = 0; index < fishList.length; index++ ) { System.out.println((Fish) fishList[index]); } // Question 3 System.out.println("Is loc1 empty? " + env.isEmpty(loc1)); // Question 4 System.out.println("Is loc3 empty? " + env.isEmpty(loc3)); // Question 5 System.out.println("The object at loc2 is " + (Fish)env.objectAt(loc2)); // Question 6 (documentation says should return null) System.out.println("The object at loc3 is " + (Fish)env.objectAt(loc3)); } }