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

Lesson 2 - The Location Class

GridWorld - Lesson 2 - The Location Class

Instructions: Break the students into teams of 3 and have them answer the following questions. They will each have a "huge" sticky notepad that they will write their answers. Call the time and have each team place their large sticky note on the wall. Go around room and have teams explain their answers question-by-question. Come up as whole with common answer - everyone agree? Move on to next question. Keep score for accuracy. Team with most questions correct, wins the prize you have chosen!


For the problem below, use the following code:

Location loc1 = new Location(12, 3);
Location loc2 = new Location(8, 3);
Location loc3 = new Location(12, 1);
Location loc4 = new location( loc3.getRow( ), loc3.getCol( ) + 2);


1. What is returned by loc1.equals(loc2)?'

2. What is returned by loc1.compareTo(loc2)?

3. What is returned by loc1.compareto(loc3)?

4. What is returned by loc1.equals(loc4)?

5. What is returned by loc1 == loc4?

6. Which of the following are legitimate ways to specify a direction of 45 degrees toward the upper left? (There may be more than one answer.):
    A. 45
    B. -45
    C. Location.NORTHEAST
    D. Location.NORTHWEST
    E. NORTHWEST
    F. Location.LEFT + Location.HALF_RIGHT


7. Using Location methods, write code that will store in int i the product of the rows in loc1 and the number of columns in loc4.

8. What is the (row, column) position of loc after the following statement is executed?
    Location loc = loc1.getAdjacentLocation(Location.East);


9. What is the (row, column)position of loc after the following statement is executed?
    Location loc = loc1.getAdjacentLocation(Location.West + Location.RIGHT);


10. how would you determine if the row position of loc1 is even or odd?

11. What is stored in dir by the following?
    int dir = loc1.getDirectionToward(loc3);


12. What is stored in dir by the following?
    int dir = loc1.getDirectionToward(new location(13, 4) );



Link to this Page