Wednesday 16 February 2011

Gridworld Part III

Gridworld: Part 3: Classes & Interfaces: Set 3: Page 19




1.

Location loc1 = new Location(4, 3);
Location loc2 = new Location(3, 4);

How would you access the row value for loc1?  

2.
Location loc1 = new Location(4, 3);
Location loc2 = new Location(3, 4);

What is the value of  b  after the following statement is executed?

boolean b = loc1.equals(loc2);


3.
Location loc1 = new Location(4, 3);
Location loc2 = new Location(3, 4);

What is the value of loc3  after the following statement is executed?

Location loc3 = loc2.getAdjacentLocation(Location.SOUTH);

4.
Location loc1 = new Location(4, 3);
Location loc2 = new Location(3, 4);


What is the value of dir  after the following statement is executed?

int dir = loc1.getDirectionToward(new Location(6, 5));

5. How does the getAdjacentLocation()  method know which adjacent location to return?  


Gridworld: Part 3: Classes & Interfaces: Set 4: Page 21



1. How can you obtain a count of the objects in a grid? How can you obtain a count of the empty locations in a bounded grid?

2. How can you check if location (10,10) is in a grid?  

3. Grid contains method declarations, but no code is supplied in the methods.

Why?

Where can you find the implementations of these methods?

4. All methods that return multiple objects return them in an ArrayList.  

Do you think it would be a better design to return the objects in an array?

Explain your answer.  



Gridworld: Part 3: Classes & Interfaces: Set 5: Page 23

 




1
What methods are implemented inCritter?  

2
What are the five basic actions common to all critters when they act?  

3
Should subclasses of Critter override thegetActors()   method?

Explain

4
Describe three ways that a critter could process actors.  

5
What three methods must be invoked to make a critter move?

Explain each of  these methods.  

6
Why is there no Critter constructor?  




Gridworld: Part 3: Classes & Interfaces: Set 6: Page 25-26




1
Which statement(s) in the canMove() method ensures that a bug does not try to move out of its grid?  

2
Which statement(s) in the canMove()method determines that a bug will not walk into a rock?  

3
Which methods of the Grid  interface are invoked by the canMove()  method and why?  

4
Which method of the Location  class is invoked by the canMove() method and why?  

5
Which methods inherited from the Actor class are invoked in the canMove()method?  

6
What happens in the move() method when the location immediately in front of the bug is out of the grid?  

7
Is the variable loc needed in the move()method, or could it be avoided by callinggetLocation() multiple times?  

8
Why do you think the flowers that are dropped by a bug have the same color as the bug?  

9
When a bug removes itself from the grid, will it place a flower into its previous location?  

10
Which statement(s) in the  move() method places the flower into the grid at the bug’s previous location?  

11
If a bug needs to turn 180 degrees, how many times should it call the turn()method?  

12



No comments:

Post a Comment