/** Chapter 2, Exercise Set 2, Question 2 * Write a simple driver program that constructs a BoundedEnv * environment and then tests answers to Analysis Question Set 3. **/ public class Ch2ExSet2Q2 { // 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); // Add more fish Fish f3 = new Fish(env, new Location(0, 0)); Fish f4 = new Fish(env, new Location(2, 7)); Fish f5 = new Fish(env, new Location(7, 7)); // 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]); } // Now remove some fish and print all objects again env.remove(f2); env.remove(f4); System.out.println("After removing f2 and f4, " + "objects in the environment are: ") ; fishList = env.allObjects(); for ( int index = 0; index < fishList.length; index++ ) { System.out.println((Fish)fishList[index]); } System.out.println("Is the location of f1 empty? " + env.isEmpty(f1.location())); System.out.println("Is the location of f2 empty? " + env.isEmpty(f2.location())); } }