Create a RandomBug class that extends the Bug class in the GridWorld program. In this extended class,

Question:

Create a RandomBug class that extends the Bug class in the GridWorld program. 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).

Implement a RandomBugRunner class to drive your new RandomBug class. In this class’s main method, instantiate an ActorWorld object named 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 11.15, 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 11.15:

public static void insertion Sort(int[] list) { int itemToInsert; int j; for (int i=1; i 0 && item To Insert

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: