Lesson 3 Key
Lesson 3 - The Grid Interface
Exercise Key, Chapter 4
1. isValid( new Location(5, 13) )
2. ArrayList aryLst = getOccupiedLocations( );
3. getOccupiedLocations retuns all such location in the entire grid. getOccupiedAdjacentLocations returns only the immediately adjacent occupied locations (maximum of eight) relative to a specified Location.
4. 600, assuming there would be an object in each cell
5. Subtract the answer in #2 from getNumRows( ) getNumCols( ).
6. Itís an Interface. An Interface has no code.
7. BoundedGrid, UnboundedGrid
9. Location.NORTH, Location.NORTHEAST, Location.EAST, Location.SOUTHEAST, Location.SOUTH, Location.SOUTHWEST,
10. An ordinary array must be predimensioned, and it is not known beforehand how big to make it. The ArrayList automatically adjusts in size as objects are added.
11. boolean objectsPresent = false:
for( Location loc : aryLst )
if( get(loc) != null )
objectsPresent = true;
Link to this Page
- Beth Zullo last edited on 25 July 2008 at 9:55 am by 22.214.171.124.transedge.com