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

Lesson 3 Key

Lesson 3 - The Grid Interface
Exercise Key, Chapter 4

1. isValid( new Location(5, 13) )

2. ArrayList aryLst = getOccupiedLocations( );
System.out.println(aryLst.size);

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

8. -1

9. Location.NORTH, Location.NORTHEAST, Location.EAST, Location.SOUTHEAST, Location.SOUTH, Location.SOUTHWEST,
Location.WEST, Location.NORTHWEST

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;
    break;
    }
    }
    System.out.println(objectsPresent);


Link to this Page