The roadways (normally made of trees) in Clara’s world often seem to be in need of repair, and it might be fun to see if Clara can fill potholes in her abstract world. For example, imagine that Clara is standing on the “road” shown in Figure 1, one corner to the left of a pothole in the road. Clara’s job is to fill the hole with a leaf and proceed to the next corner. Figure 2 illustrates how the world should look after the program execution.

University/Course: WSU

Uploaded: October 28, 2024

Files: 1

✓ Solution:

/* PERMITTED COMMANDS

   move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
   JAVA
   if, while, for
*/
class MyClara extends Clara {
    void run() {
        fixPotholes();
    }

 

    void fixPotholes() {
        if (onLeaf()) {
            removeLeaf();
        }

 

        while (!treeFront()) {

🔒 Whatsapp us for the full file.