Lesson 4 - The Actor Class
GridWorld - Lesson 4- The Actor Class
(Appendix D will need to be referred to as the following questions pertain to code found there):
1. Which line of code in the canMove method of the Bug class in Appendix D is most reponsible for not allowing a move into a cell that contains a Rock or another Bug.
2. In the canMove method of the Bug class in Appendix D, what is the significance of Location loc given by?
Location loc = getLocation( );
3. In which method of the Bug class in Appendix D is a Flower removed when moving an object to the Location occupied by the Flower?
4. Show that portion of the code in the canMove method of the Bug class used to determine the object occupying the position to which we wish to move.
5. What portion of the code in the canMove method of the Bug class is responsible for not allowing a move to an invalid Location?
6. In the move method of the Bug class, what happens if the mvoe method is called without previously "getting permission" by calling canMove, and the resulting move would be to an invalid Location on the Grid?
7. For a Bug originally pointed north, how many times must the turn method be executed in order for the Bug to be pointed West?
8. What code evidence could you offer that the color of a Flower dropped bya Bug is the same color as the Bug?
9. When a Bug moves to a new cell it leaves behind a Flower in the cell it is vacating. Which method of the Bug class accomplishes this, and with what code?
10. Modify the code in the move method of the Bug class, eliminating the line: Location loc = getLocation();; Rewrite the remaining two lines of code that used loc by calling getLocation instead.
11. What does the act method of the Rock class do?
12. If a Bug removes itself from the Grid in its move method, does it still leave a Flower behind?
13. What does the act method of the Flower class do?
Link to this Page
- Beth Zullo last edited on 25 July 2008 at 9:55 am by 22.214.171.124.transedge.com