Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please find the solution for this ASAP I need help and only use the permitted commands to answer this question Clara arrives in a city

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Please find the solution for this ASAP I need help and only use the permitted commands to answer this question

Clara arrives in a city of Roadville, which is very famous for terrible roads. She decides to fix the situation and starts with the main road at the beginning of which she currently stands. The road is represented by 5 lines of trees underneath Clara, but there are holes of different depth in this road at various places. Figure 1 shows an example of Clara's original position and the road with holes in it. Figure 1. Your mission is to write a program that instructs Clara to fill all the holes in this road with leaves as shown in Figure 2. At the end of every road that Clara has to fix is a mushroom. She must use this mushroom as an indicator that it's time to stop fixing the road. A mushroom can be sensed with mushroomFront() command. Figure 2. Your solution must be generic and must work on any road with an arbitrary number of holes of various depths. You can use the supplied example worlds to test whether your solution is generic. For solving this exercise you can use standard Java command + additional commands from Clara's vocabulary. Clara's vocabulary: - turnLeft(); Clara turns 90 degrees to the left - move(); Clara moves one step forward in the direction she is currently facing - putLeaf(); Clara puts one leaf at her current position - removeLeaf(); Clara removes a leaf at her current position - turnRight(); Clara turns 90 degrees to the right - onLeaf(); Returns true if Clara is positioned on top of a leaf or false otherwise - treeFront(); Returns true if there is a tree one step ahead in the direction Clara faces or false otherwise - treeLeft(); Returns true if there is a tree to the left from Clara or false otherwise - treeRight(); Returns true if there is a tree to the right from Clara or false otherwise - mushroomFront(); Returns true if there is a mushroom in front of Clara or false otherwise Feel free to try each of these commands by putting them inside the run method, switching to the board tab and then clicking the "Run" button. Commands like onLeaf(), treeFront(), treeLeft(), treeRight() and mushroomFront() should be used either inside an if statement or as a loop condition. For example: if ( !treeFront()) move(); while (onLeaf()) { move(); } /* PERMITTED COMMANDS Clara commands: move(); turnLeft(); turnRight(); treeLeft(); treeRight(); treeFront(); onLeaf(); putLeaf(); removeLeaf(); mushroomFront(); JAVA commands: if, while, for, do, !,, \&\& / class MyClara extends Clara \{ /** * In the 'run()' method you can write your program for Clara */ void run() \{ // TOD0: Write your code below Clara arrives in a city of Roadville, which is very famous for terrible roads. She decides to fix the situation and starts with the main road at the beginning of which she currently stands. The road is represented by 5 lines of trees underneath Clara, but there are holes of different depth in this road at various places. Figure 1 shows an example of Clara's original position and the road with holes in it. Figure 1. Your mission is to write a program that instructs Clara to fill all the holes in this road with leaves as shown in Figure 2. At the end of every road that Clara has to fix is a mushroom. She must use this mushroom as an indicator that it's time to stop fixing the road. A mushroom can be sensed with mushroomFront() command. Figure 2. Your solution must be generic and must work on any road with an arbitrary number of holes of various depths. You can use the supplied example worlds to test whether your solution is generic. For solving this exercise you can use standard Java command + additional commands from Clara's vocabulary. Clara's vocabulary: - turnLeft(); Clara turns 90 degrees to the left - move(); Clara moves one step forward in the direction she is currently facing - putLeaf(); Clara puts one leaf at her current position - removeLeaf(); Clara removes a leaf at her current position - turnRight(); Clara turns 90 degrees to the right - onLeaf(); Returns true if Clara is positioned on top of a leaf or false otherwise - treeFront(); Returns true if there is a tree one step ahead in the direction Clara faces or false otherwise - treeLeft(); Returns true if there is a tree to the left from Clara or false otherwise - treeRight(); Returns true if there is a tree to the right from Clara or false otherwise - mushroomFront(); Returns true if there is a mushroom in front of Clara or false otherwise Feel free to try each of these commands by putting them inside the run method, switching to the board tab and then clicking the "Run" button. Commands like onLeaf(), treeFront(), treeLeft(), treeRight() and mushroomFront() should be used either inside an if statement or as a loop condition. For example: if ( !treeFront()) move(); while (onLeaf()) { move(); } /* PERMITTED COMMANDS Clara commands: move(); turnLeft(); turnRight(); treeLeft(); treeRight(); treeFront(); onLeaf(); putLeaf(); removeLeaf(); mushroomFront(); JAVA commands: if, while, for, do, !,, \&\& / class MyClara extends Clara \{ /** * In the 'run()' method you can write your program for Clara */ void run() \{ // TOD0: Write your code below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the testing process of accounting 2?

Answered: 1 week ago