Sunteți pe pagina 1din 5

Do you Know?

Set 5 (page 23)


Name: _________________________________________________ Period: _______ The API for the Actor class is in Appendix B. 1. Name three properties of every actor. Actors have colors, directions, and locations. 2. When an actor is constructed, what is its direction and color? Actors are initially blue and north. 3. Why do you think that the Actor class was created as a class instead of an interface? You cant do anything to the Actor if it was an interface. 4. Can an actor put itself into a grid twice without first removing itself? If the actor is in the grid, its in the grid. Theres no logic or possibility in putting the very same actor in another grid, occupying two at the same time. Can an actor remove itself from a grid twice? Like the previous question, its not possible nor logical. Can an actor be placed into a grid, remove itself, and then put itself back? Try it out. What happens? It can and it should be fine. 5. How can an actor turn 90 degrees to the right? Use the setDirection() method.

2007 The College Board. All rights reserved. Visit apcentral.collegeboard.com (for AP professionals) and www.collegeboard.com/apstudents (for AP students and parents).

Do you Know? Set 6 (page 25)


Name: _________________________________________________ Period: _______ The source code for the Bug class is in Appendix C. 1. Which statement(s) in the canMove method ensures that a bug does not try to move out of its grid? if(!gr.isValid(next)) return false; 2. Which statement(s) in the canMove method determines that a bug will not walk into a rock? Actor neighbor=gr.get(next); return(neighbor==null)||(neighbor instanceof Flower); 3. Which methods of the Grid interface are invoked by the canMove method and why? isValid() and get() methods are invoked. They are needed to ensure that nothing is in the way of the actor. 4. Which method of the Location class is invoked by the canMove method and why? getAdjacentLocation() method is used because the canMove() method needs to check the Surrounding locations if its vacant and thus allowable to move into. 5. Which methods inherited from the Actor class are invoked by the canMove method? getLocation(), getDirection() and getGrid() methods are used for obvious reasons; the whole point is focused around said point. 6. What happens in the move method when the location immediately in front of the bug is out of the grid? The bug will be removed 7. Is the variable loc needed in the move method, or could it be avoided by calling getLocation() multiple times?
2007 The College Board. All rights reserved. Visit apcentral.collegeboard.com (for AP professionals) and www.collegeboard.com/apstudents (for AP students and parents).

I think it is. From what I remember, the loc variable is required to actually retain the actual location as a finite variable whereas the getLocation() retrieves it objectively. 8. Why do you think the flowers that are dropped by a bug have the same color as the bug? Its easier to distinguish who comes from who? 9. When a bug removes itself from the grid, will it place a flower in its previous location? I dont think so? The flower comes out following an act method or move. So if the bug is instantaneously removed, there shouldnt be a flower there. 10. Which statement(s) in the move method places the flower in the grid in the bugs previous location? Flower flower=new Flower(getColor()); Flower.putSelfInGrid(gr,loc); 11. If a bug needs to turn 180 degrees, how many times should it call the turn method? 4 times

2007 The College Board. All rights reserved. Visit apcentral.collegeboard.com (for AP professionals) and www.collegeboard.com/apstudents (for AP students and parents).

Group Activity Ch 3 (page 26)


Name: _________________________________________________ Period: _______ Name: _________________________________________________ Name: _________________________________________________ Name: _________________________________________________ Name: _________________________________________________

1. Specify: Each group creates a class called Jumper. This actor can move forward two cells in each move. It jumps over rocks and flowers. It does not leave anything behind it when it jumps. In the small groups, discuss and clarify the details of the problem: a. What will a jumper do if the location in front of it is empty, but the location two cells in front contains a flower or a rock? If it was a bug maybe it could turn? b. What will a jumper do if the location two cells in front of the jumper is out of the grid? It could turn. c. What will a jumper do if it is facing an edge of the grid? It could turn. d. What will a jumper do if another actor (not a flower or a rock) is in the cell that is two cells in front of the jumper? It could turn, take the place of that other actor if coded to do so or nothing.

2007 The College Board. All rights reserved. Visit apcentral.collegeboard.com (for AP professionals) and www.collegeboard.com/apstudents (for AP students and parents).

e. What will a jumper do if it encounters another jumper in its path? It depends on the coding of the jumper. If it can eat its own then itll replace the other. f. Are there any other tests the jumper needs to make? Can Jumper go one at a time in any instance? Can it go locations with other actors? Design: Groups address important design decisions to solve the problem: g. Which class should Jumper extend? Why? It definitely extends actor. Maybe bug? It acts and sounds like one. h. Is there an existing class that is similar to the Jumper class? If so, which one? Why or why not? JumpingBug along with the original bug sounds similar to the Jumper. canMove() and in Jumpers possible case, canJump() seem to have a funny correlation. i. Should there be a constructor? Why? If yes, what parameters should be specified for the constructor? I guess there can. You can always make the jumper do extra stuff like change color or something. In that case youd need a color parameter. j. Which methods should be overridden? Why? The canMove() and move() method should be overridden because the Jumper jumps. k. What methods, if any, should be added? Why? I cant think of anything else besides move-related methods. l. What is the plan for testing the class? Just make a jumper class as well as a jumpertester. Then run the jumpertester and see if it goes.

2007 The College Board. All rights reserved. Visit apcentral.collegeboard.com (for AP professionals) and www.collegeboard.com/apstudents (for AP students and parents).

S-ar putea să vă placă și