Problem

(Case Study) Create a RandomBug class that extends the Bug class in GridWorld. In this ext...

(Case Study) Create a

RandomBug
class that extends the
Bug
class in GridWorld. In this extended class, override the
move
method inherited from
Bug.
Do this by copying the code from
Bug’s move
method and then replacing the code fragment that creates flowers and deposits them in the bug’s wake with a
setDirection
call that randomly selects one of the directions, 0, 45, 90, 135, 180, 225, 270, or 315. Get a random value the same way that
GridWorld
gets a random value for a bounded grid in the
World
class’s
getRandomEmptyLocation
method. But instead of using

generator.nextInt (emptyLocs.size())

use

45 * generator.nextint (8)

Also create a

RandomBugRunner
class to exercise your new
RandomBug
class. In this class’s
main
method, instantiate an
ActorWorld
object called world. Then have
world add
ten
RandomBug
objects, and then have
world
call its
show
method.

Executing

RandomBugRunner
should generate a display similar to that in Figure, except this time there will be ten randomly located bugs and no rock. Push the
Step
button a few times to see how the bugs move. Then click
World > UnboundedGrid,
adjust the sliders on the sides to move the cluster of bugs to the center of the larger display, click
Run,
and watch the bugs gradually spread apart as time passes.

Figure Tree class-part A.

This class provides the model. It describes the components whose behavior the program simulates.

Figure Tree class-part B.

The drawBranches method defines the recursion that describes a tree at any one time.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 13
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT