# Jeopardy - PowerPoint PPT Presentation

1 / 53
Jeopardy

## Jeopardy

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. Jeopardy AP Computer Science editionGridWorld Bug Variations (Ch2)

2. Bug Grid Location Actor BoxBug 100 100 100 100 100 200 200 200 200 200 Jeopardy 300 300 300 300 300 400 400 400 400 400 500 500 500 500 500

3. How many constructor methods does a Bug have and what do they do? Bug - 100

4. What is the purpose of the act() method and what does it do for a standard Bug? Bug - 200

5. A standard Bug is facing a rock and the bug is told to move(). What will happen? Bug - 400

6. If you create a new Bug and redefined the turn() method as follows, what would be the behavior of the bug? public void turn(){ setDirection(getDirection() * 2);} Bug - 500

7. What is the Grid method used to retrieve an object at a location on the grid? Grid - 100

8. In a bug class, how would you determine if Location loc is outside the grid? Grid - 200

9. In a bug class how would you determine how many columns are in the world that the bug inhabits? Grid - 500

10. What Location method(s) are used in the Bug’s move() method? Location - 100

11. In a Bug class, how could you determine if the bug is on the first row (assume a bounded grid)? Location - 200

12. In a Bug class, how could you determine if the bug is on a location where the row and the column were the same? Location - 300

13. How can you determine if the object to the left of the bug is a Critter? Location - 500

14. How can the bug be taken out of ActorWorld? Actor - 200

15. How can you make the Bug move to the previous column on the same row and stay in the direction it is facing? Actor - 300

16. What happens here?Grid<Actor> gr = new BoundedGrid(20,20);ActorWorld world = new ActorWorld(gr);world.add(new Location(2,2), new Rock);Bug ladyBug = new Bug();ladyBug.putSelfInGrid(gr, new Location(2,2));ladyBug.putSelfInGrid(gr, new Location(3,4)); Actor - 400

17. How can you make the Bug move to the last row in the grid, stay in the same column it is in, and stay in the direction it is currently facing? Actor - 500

18. What is the parameter passed to a new BoxBug and what does it mean? BoxBug -100

19. What does the instance variable steps represent? BoxBug - 200

20. Can the path that a BoxBug takes ever change? BoxBug – 400

21. When will the value of steps be zero? BoxBug – 500

22. Thanks

23. How many constructor methods does a Bug have and what do they do? Bug – 100 (solution) 2 Constructor Methods: Bug() – creates a red bug facing north Bug(Color) - creates a bug of the specified color which faces north

24. What is the purpose of the act() method and what does it do for a standard Bug? Bug – 200 (solution) The act() method controls the behavior of the bug. The standard behavior is that the bug moves in the direction it is facing if it can, else it turns 45 degrees to the right.

25. When does the canMove() method return false? Bug – 300 (solution) When the border is directly in front of the bug or when another actor other than a flower is in front of the bug.

26. A standard Bug is facing a rock and the bug is told to move(). What will happen? Bug – 400 (solution) The rock will be removed from the grid and the Bug will move to the spot where the rock was originally located

27. If you create a new Bug and redefined the turn() method as follows, what would be the behavior of the bug? public void turn(){ setDirection(getDirection() * 2);} Bug – 500 (solution) The higher the number of degrees the bug was facing (up to 359) the more the bug would turn (by a factor of 2)

28. What is the Grid method used to retrieve an object at a location on the grid? Grid – 100 (solution) get(Location) – It will return the object at that location, or null if there is no object at that location.

29. In a bug class, how would you determine if Location loc is outside the grid? Grid – 200 (solution) Grid<Actor> gr = getGrid();if (!gr.isValid(loc)) ……….

30. How do you create a world which has no boundaries? Grid – 300 (solution) ActorWorld world = new ActorWorld(new UnboundedGrid());

31. How do you create a world which has 30 rows and 30 columns? Grid – 400 (solution) ActorWorld world = new ActorWorld(new BoundedGrid(30,30));

32. In a bug class how would you determine how many columns are in the world that the bug inhabits? Grid – 500 (solution) Grid<Actor> gr = getGrid();int numColumns = gr.getNumCols();

33. What Location method(s) are used in the Bug’s move() method? Location – 100 (solution) getAdjacentLocation()

34. In a Bug class, how could you determine if the bug is on the first row (assume a bounded grid)? Location – 200 (solution) if (getLocation().getRow() == 0) …….

35. In a Bug class, how could you determine if the bug is on a location where the row and the column were the same? Location – 300 (solution) Location loc = getLocation();if (loc.getRow() == loc.getCol()) …….

36. How do you determine the location directly behind the bug? Location – 400 (solution) Location loc = getLocation(); Location backLoc = loc.getAdjacentLocation(getDirection()+180);

37. How can you determine if the object to the left of the bug is a Critter? Location – 500 (solution) Grid<Actor> gr = getGrid();Location loc = getLocation(); Location leftLoc = loc.getAdjacentLocation(getDirection()-90);if (gr.get(leftLoc) instanceof Critter) ……..

38. How do you determine the grid that the actor is located on? Actor – 100 (solution) Grid<Actor> gr = getGrid();// gr now conatins the grid that the actor is on or null if it is not on a grid.

39. How can the bug be taken out of ActorWorld? Actor – 200 (solution) removeSelfFromGrid();

40. How can you make the Bug move to the previous column on the same row and stay in the direction it is facing? Actor – 300 (solution) Location loc = getLocation();moveTo(new Location(loc.getRow(), loc.getCol()-1));

41. What happens here?Grid<Actor> gr = new BoundedGrid(20,20);ActorWorld world = new ActorWorld(gr);world.add(new Location(2,2), new Rock);Bug ladyBug = new Bug();ladyBug.putSelfInGrid(gr, new Location(2,2));ladyBug.putSelfInGrid(gr, new Location(3,4)); Actor – 400 (solution) The rock is removed from location (2,2).ladyBug is put into location (2,2).An error occurs when the last line of code is executed, since ladyBug already exists in the grid.

42. How can you make the Bug move to the last row in the grid, stay in the same column it is in, and stay in the direction it is currently facing? Actor – 500 (solution) Grid<Actor> gr = getGrid();Location loc = getLocation();moveTo(new Location(gr.getNumRows()-1, loc.getCol()));

43. What is the parameter passed to a new BoxBug and what does it mean? BoxBug – 100 (solution) The parameter is an integer and it represents the number of steps the BoxBug takes on each side of the box.

44. What does the instance variable steps represent? BoxBug – 200 (solution) steps is an integer that represents the number of steps the BoxBug has currently taken on a side of a box.