1. A bug may not always move to
a new location. List the two situations below in which a bug
will move to
a new location.
a.
A bug will only move to the
location in front of it if the cell exists and is empty
b.
Or, there is a flower in the
cell.
2. In which direction does the bug
move?
A bug
attempts to move forward.
3. What does the bug do if it does
not move?
When a bug
cannot move, it turns 45 degrees to the right.
4. A bug moves
a.
What does it leave behind when it moves.
A bug leaves a flower in its old cell when it moves to a new cell.
b.
What is the color of the object it leaves behind?
The flower is the same color as the bug.
5 . Can more than one actor (bug, flower, rock) be in the same location in
the grid at the same
time?
No. A
location in the grid can contain only one actor at a time.
6. Assume the following
statements to answer the following 2 questions.
Location
loc1 = new Location(4,3);
Location
loc2 = new Location(3,4);
a.
Write the code to access the row value for loc1?
loc1.getRow()
b.
What is the value of b after the following statement is executed?
boolean b = loc1.equals(loc2);
false
7. Which of the following is a
false statement about Rock and
Flower behavior?
a.
When a rock acts, it does nothing.
b.
When a flower acts, it does nothing.
Answer
c.
A flower never changes its location when it acts.
d.
A rock never changes its location when it acts.
e.
When a rock is placed in a location that contains a flower, the
flower disappears from the
grid.
8. Suppose a bug starts out
facing south. If the turn method is called for this bug, what will its
resulting
direction be?
a.
North
b.
Northeast
c.
Northwest
d.
Southeast
e.
Southwest
Answer
9. What will be the effect of
executing the following statement in a client class for Bug and
BoxBug?
Big bb = new
BoxBug
a.
A red BoxBug facing north will be created, with random sideLength.
b.
A red BoxBug facing north will be created, with a sideLength = 0.
c.
A red BoxBug with random direction will be created, with sideLength =
0.
d.
A BoxBug with random color and direction will be created, with
sideLength = 0.
e.
A compile-time error will occur.
Answer
10. What is a good reason for
using the Location class constants for the compass directions
and commonly used turn angles?
I. They enhance
readability of code.
II. There is no built-in Degree
type in Java.
III. They distinguish locations from directions.
a. I only
Answer
b. II only
c. III only
d. I and III only
e. I, II, and III
11. Given the following grid,
occupied as indicated. The row and column numbers are
indicated.
|
0 |
1 |
2 |
0 |
|
Rock |
|
1 |
|
Bug |
Flower |
2 |
|
|
|
Which location will the bug occupy after it acts once?
a. (1,1)
Answer
b. (0,1)
c. (1,2)
d. (2,1)
e. (1,0)
12. Suppose you want to modify
the behavior of a Bug as follows:
Every time it moves to a
new location, it drops a rock rather than a Flower into its old location.
Which of the following
modifications to the move method of the Bug class will correctly achieve
this?
I. Replace the last two
"flower" lines with
Rock rock = new Rock();
rock.putSelfInGrid(gr, loc);
II. Replace the last two
"flower" lines with
Rock rock = new Rock();
gr.put(loc,
rock);
III. Replace the last two "flower" lines with
Rock rock = new Rock();
gr[loc.getRow()] [loc.getCol()] = rock;
a. I only
Answer
b. II only
c. III only
d. I and II only
e. I, II, and III
13. In which of the following
situations will the canMove method of bug return true?
The direction in which the bug is facing in each situation is as indicated.
I: bug facing NE
|
II: bug facing S
|
III: bug facing W
|
a. I only
b. II only
c. III only
d. I and II only
e. II and III only
Answer
14. What would be the effect of
having a subclass of Actor called SubActor that does not
override the act method?
I. A SubActor object
would always be blue.
II. A SubActor object would
always face north.
III. A SubActor object would remain in its original location when it acts.
a. I only
b. II only
c. III only
Answer
d. I and III only
e. I, II, and III
Extra Credit
1. How much time, in minutes,
is allotted for the multiple-choice portion of the AP computer
science
exam?
__________ minutes
75
2. How much time, in minutes,
is allotted for the free-response portion of the AP computer
science
exam?
__________ minutes
105
3. How many questions are on
the multiple-choice portion of the AP computer science exam?
_________
40
4. A picture of the primary developer of the Java language is shown
on the
right.
What is
the name of this computer scientist?
________________________________
James Gosling |
|
5. GUI developers usually write
code to fit their impressions of the world with the aim, however,
of making
things reasonably clear. What is probably the name of the following object
or
objects on
the cover page of this review exercise?
a.
Object 1:_________________________________________
rock
b.
Object 2:_________________________________________
bug
c.
Object 3:_________________________________________
flower