In this problem you continue learning conditional statements. Now Clara appears in a world similar to the one shown in Figure 1. She prepares for a long winter and her task is to make leaf provision. The problem is that other bugs will eat any leaf she doesn’t hide under a tree. So the task for Clara is to remove all leaves that do not have a tree above them. Looking from the Clara’s position shown in Figure 1. this means moving forward and removing all leaves at Clara’s position when there is no tree to the left from this position. Once Clara detects that there is a tree ahead of her, she has to stop. The result should look similar to Figure 2. As in the previous problem you have a choice of 3 different worlds and your code must produce correct Clara behaviour in all three examples. Your tutor might also want to test how generic your approach is by moving trees and leaves around in a random fashion, so make sure you produce a general-purpose solution that works with any possible world configuration (all worlds are two cells high, trees only appear at the top and leaves at the bottom row).

University/Course: WSU

Uploaded: October 27, 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
  move();
    if(!treeLeft()&&onLeaf())

🔒 Whatsapp us for the full file.