The winter has passed and Clara is no longer worried about hiding her leaves under trees, but she is now obsessed with putting them in order. In this problem Clara starts in a world shown in Figure 1. Your task is to help Clara to put leaves in a straight line as shown in Figure 2. Remember to only use permitted commands and don’t put leaves on top of one another. Clara should stop once she encounters a tree in front of her. One of the challenges in this exercise will be to write your code so that you don't forget to put the last leaf (just ahead of the tree). It is not really visible in Figure 2, but there is a leaf underneath Clara at her final position.

University/Course: WSU

Uploaded: November 2, 2024

Files: 1

✓ Solution:

/* PERMITTED COMMANDS
   move, stop, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront
   JAVA
   if, else, &&, ||, ! */
   
class MyClara extends Clara { 
    /**
     * In the ‘act()’ function you can write your program for Clara 
     */
    void act() {
        // TODO: Write your code below
     if(!onLeaf())
     putLeaf();

🔒 Whatsapp us for the full file.