View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

Lesson 3 - The Grid Interface

GridWorld - Lesson 3- The Grid Interface


1. What code will determine if Location(5,13) is on the Grid?

2. Write code that will print the total number of objects in a Grid.

3. What is the difference between the two methods, and getOccupiedAdjacentLocations?

4. In a Grid of 20 rows by 30 columns, what would be the maximum number of objects in the ArrayList that getOccupiedlocations could return?

5. How could the number of empty cells ina Grid be determined?

6. Why does Grid not have any code?

7. What classes have full implementation of Grid?

8. What do getRows( ) and GetCols( ) return for an UnboundedGrid?

9. The validAdjacentLocations method can have a many as eight elements in its returned ArrayList object. Using Location constants, list the directions of these eight cells relative to the specified Location.

10. Sever of the methods of the Grid Interface return and ArrayList object. What advantage does this have over an ordinary array?

11. Suppose an ArrayList object called aryLst is returned by getValidAdjacentLocations(). Using an enhanced for-loop, show how to iterate through the location objects in aryLst and determine if any objects are in the list. Print true if any objects are present; otherwise print false.

Link to this Page