/** Chapter 2, Exercise Set 3, Questions 1 and 2 * Write a simple driver program that constructs a BoundedEnv * enviromnment and then tests answers to Analysis Question Set 3. **/ import java.util.ArrayList; public class Ch2ExSet3Q1and2 { // 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 the problem Location loc1 = new Location(0, 0); Location loc2 = new Location(0, 1); Location loc3 = new Location(1, 1); // Answer Exercise Set 3 Question 1 ArrayList nbrs1 = env.neighborsOf(loc1); ArrayList nbrs2 = env.neighborsOf(loc2); ArrayList nbrs3 = env.neighborsOf(loc3); System.out.println("Location " + loc1 + " has " + nbrs1.size() + " neighbors"); System.out.println("Location " + loc2 + " has " + nbrs2.size() + " neighbors"); System.out.println("Location " + loc3 + " has " + nbrs3.size() + " neighbors"); // Answer Exercise Set 3 Question 2 System.out.print("The neighbors of location " + loc1 + " are: "); for (int index = 0; index < nbrs1.size(); index++) { System.out.print(nbrs1.get(index) + " "); } System.out.println(); System.out.print("The neighbors of location " + loc2 + " are: "); for (int index = 0; index < nbrs2.size(); index++) { System.out.print(nbrs2.get(index) + " "); } System.out.println(); System.out.print("The neighbors of location " + loc3 + " are: "); for (int index = 0; index < nbrs3.size(); index++) { System.out.print(nbrs3.get(index) + " "); } System.out.println(); } }