Answered step by step
Verified Expert Solution
Question
1 Approved Answer
As an exercise in solving algorithmic problems, program Clara to place a single leaf at the centre of her world (edges of the world
As an exercise in solving algorithmic problems, program Clara to place a single leaf at the centre of her world (edges of the world populated with trees are not considered to be a streets/avenues in this scenario). For example, if Clara starts in the world shown in Figure 1, after execution of your program the world should appear as in Figure 2. 4 4 Note that the final configuration of the world should have only a single leaf at the midpoint of Clara's world. When Clara is finished she must step away from the leaf and remain one step to the east from it. Along the way, Clara is allowed to place additional leaves wherever she wants to, but must pick them all up again before she finishes. You are required to develop a general-purpose solution that works with all supplied worlds. 4 4 4 4 4 * Figure 2. In solving this problem, you may count on the following facts about the world: Clara starts at 1st Avenue and 1st Street, facing east, with an infinite number of leaves in her bag. The initial state of the world includes no interior trees (apart from those on the border) or leaves. Your program, moreover, can assume the following simplifications: That the width of the world is always odd. The world is always square, so the width of it is always equal to height. It does not matter which direction Clara is facing at the end of the run. There are many different algorithms you can use to solve this problem. The interesting part of this assignment is to come up with a strategy that works. Please be aware that you are explicitly prohibited to use for loops and variables for solving this problem! This means that Clara is not allowed to memorise anything (e.g. how many steps she made or how wide the street is). You must solve this problem by moving around and putting or removing leaves. MyClara 1 /* PERMITTED COMMANDS 2 move(); turnLeft(); turnRight(); treeLeft(); treeRight(); treeFront (); onLeaf(); putLeaf(); removeLeaf (); JAVA if, else, while, &&, ||, ! NOT ALLOWED TO USE for-LOOPS and variables */ UAW N 3 4 5 6
Step by Step Solution
★★★★★
3.36 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
Here is a possible algorithm for Clara to place a single leaf at the center of 1st Street Move to th...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started