530 likes | 649 Views
Jeopardy. AP Computer Science edition GridWorld Bug Variations (Ch2). 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.
E N D
Jeopardy AP Computer Science editionGridWorld Bug Variations (Ch2)
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
How many constructor methods does a Bug have and what do they do? Bug - 100
What is the purpose of the act() method and what does it do for a standard Bug? Bug - 200
A standard Bug is facing a rock and the bug is told to move(). What will happen? Bug - 400
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
What is the Grid method used to retrieve an object at a location on the grid? Grid - 100
In a bug class, how would you determine if Location loc is outside the grid? Grid - 200
How do you create a world which has no boundaries? Grid - 300
How do you create a world which has 30 rows and 30 columns? Grid - 400
In a bug class how would you determine how many columns are in the world that the bug inhabits? Grid - 500
What Location method(s) are used in the Bug’s move() method? Location - 100
In a Bug class, how could you determine if the bug is on the first row (assume a bounded grid)? Location - 200
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
How do you determine the location directly behind the bug? Location - 400
How can you determine if the object to the left of the bug is a Critter? Location - 500
How do you determine the grid that the actor is located on? Actor - 100
How can the bug be taken out of ActorWorld? Actor - 200
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
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
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
What is the parameter passed to a new BoxBug and what does it mean? BoxBug -100
What does the instance variable steps represent? BoxBug - 200
What does the instance variable sideLength represent? BoxBug - 300
Can the path that a BoxBug takes ever change? BoxBug – 400
When will the value of steps be zero? BoxBug – 500
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
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.
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.
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
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)
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.
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)) ……….
How do you create a world which has no boundaries? Grid – 300 (solution) ActorWorld world = new ActorWorld(new UnboundedGrid());
How do you create a world which has 30 rows and 30 columns? Grid – 400 (solution) ActorWorld world = new ActorWorld(new BoundedGrid(30,30));
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();
What Location method(s) are used in the Bug’s move() method? Location – 100 (solution) getAdjacentLocation()
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) …….
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()) …….
How do you determine the location directly behind the bug? Location – 400 (solution) Location loc = getLocation(); Location backLoc = loc.getAdjacentLocation(getDirection()+180);
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) ……..
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.
How can the bug be taken out of ActorWorld? Actor – 200 (solution) removeSelfFromGrid();
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));
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.
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()));
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.
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.