(Case Study) Create a
RandomBugclass that extends the
Bugclass in GridWorld. In this extended class, override the
movemethod inherited from
Bug.Do this by copying the code from
Bug’s movemethod and then replacing the code fragment that creates flowers and deposits them in the bug’s wake with a
setDirectioncall that randomly selects one of the directions, 0, 45, 90, 135, 180, 225, 270, or 315. Get a random value the same way that
GridWorldgets a random value for a bounded grid in the
Worldclass’s
getRandomEmptyLocationmethod. But instead of using
generator.nextInt (emptyLocs.size())
use
45 * generator.nextint (8)
Also create a
RandomBugRunnerclass to exercise your new
RandomBugclass. In this class’s
mainmethod, instantiate an
ActorWorldobject called world. Then have
world addten
RandomBugobjects, and then have
worldcall its
showmethod.
Executing
RandomBugRunnershould 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.

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.