Important Notes:-NO NEED FOR REFERENCING- Just create a brief solution for each problem. -I have completed problem 1, but I need to do problem 2,3,4 and the bonus please. - Each of your solutions this...

Important Notes:-NO NEED FOR REFERENCING- Just create a brief solution for each problem.
-I have completed problem 1, but I need to do problem 2,3,4 and the bonus please.
- Each of your solutions this week MUST declare and successfully use at least one variable to memorise certain facts about the world or Clara’s progress (we are learning variables this week).
- Note that problem 2 must use Boolean variable (e.g. Clara facingeast = true/false).
- we have not done arithmetic arrays or operations yet so it shouldn't be necessary to use them, use them if you have to, however I must use decomposition in my solution.
- note mistake in Claras vocabulary. the command mushroomFront(); tests if there is a mushroom in front of clara, not a tree.
Problem 3 Permitted commands: move(); turnLeft(); turnRight(); treeLeft(); treeRight(); treeFront(); onLeaf(); putLeaf(); removeLeaf();

JAVA if, else, for, while, do, !, ||, && variables*/Problem 2,4, bonus permitted commands: move, turnLeft, turnRight, treeLeft, treeRight, treeFront, onLeaf, putLeaf, removeLeaf, mushroomFront JAVA if, while, for


Practical 5: Variables Practical 5: Variables 1 Practical 5: Variables 300580 Programming Fundamentals Week 6 Regular Problems In every practical, depending on your previous level of programming experience you have a choice to either complete a set of regular problems (if you are less experienced) or just to complete the Bonus problem and skip all the regular problems (if you are more experienced). A summary of marks for all regular problems is equal to the mark obtained for completing the bonus problem. If you want to maximise your chances of getting a high mark – you may consider completing all regular problems as well as the bonus problem. In this case mark deductions obtained in the regular problems can be compensated by the bonus problem. Note, however, that even if you produce no mistakes in all solutions – you can’t obtain more than the maximum number of points allocated for all regular problems combined (10 points in this practical). Important Note Each of your solutions this week MUST declare and successfully use at least one variable to memorise certain facts about the world or Clara’s progress. Correct use of variables is critical and your mark will be heavily dependent on this factor. Clara’s vocabulary This week Clara can use the following commands • 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 tree to the right from Clara or false otherwise Please see the header of MyClara.java to test which of these commands can be used for each problem. Practical 5: Variables 2 Problem 1 – Counting Trees (2 points) While you have already encountered variables in other problems (usually within loops) – this problem is designed to be one of your first conscious uses of the variable concept. Clara’s task is to count the trees that on the rows above and below her. You will be presented with a scenario similar to the one shown in Figure 1.1. Figure 1.1. Initial screen In this world there is always only a street with one tree at the start, and one tree at the end. Clara must move from left to right and count all the trees above and below her. The street always ends with a tree, so use it as an indicator for when Clara should stop. Figure 1.2. Final Screen Once the trees have been counted – use System.out.println(); call to present the result as shown in Figure 2. Please note that your output should exactly match the format of the output shown in Figure 1.2 and the number displayed there must match the number of trees above and below Clara. Your solution must be generic. There are other worlds included with this problem, so your code must work with all of them without modification. Problem 2 – Invert Field (2 points) This problem continues to test you in regards to code decomposition strategies, use of variables and possibly code modification. Clara’s task is to invert her world. This means putting a leaf in every empty cell and removing a leaf from every non-empty cell. While producing your solution for this problem you must use at least one variable (a good idea is to make this variable of type boolean). This variable should be used to help Clara in memorising the direction of her current movement. The simplest way to approach this problem is to base your solution around the sample code for ClaraCleaner from Lecture 3. But here, instead of cleaning the world you must invert it and you must make use of the variable that you declare in order to decide on whether to reposition Clara to the east or to the west, rather than Practical 5: Variables 3 looking at the trees around her to make this decision. Once you do it – make sure you clean up all the unnecessary code from the base solution. Figure 2.1. Initial screen Figure 2.2. Final Screen The initial configuration is shown in Figure 2.1 and the result should look similar to Figure 2.2. Clara always starts at the upper left corner facing east. Your program should be generic enough to handle any world configuration. Example worlds supplied with this problem will help you to test your code. Problem 3 – Longest Step (3 points) Here we continue with variable use. Clara is learning a new trade; she is about to become a carpenter. One of the tasks set out for her is to measure the length of the longest step in the set of stairs leading to the entry of her house. Apparently, the steps in her staircase are all different and she will later have to fix this problem. But for now, she just has to measure them all and find the longest one. Figure 3.1. Initial screen Figure 3.2. Final Screen Practical 5: Variables 4 Clara starts in the world as shown in Figure 3.1. She must move from west to east and once reaching the top right corner – she must present the value of the longest step in the staircase she has climbed. The outcome should resemble what is shown in Figure 3.2. Clara has to measure the length of each step and print the result using the System.out.println() command. Your solution must be generic and work with all supplied example worlds. Your output should also perfectly match the format "longest step = x" in order for our system to be able to validate it properly. Problem 4 – Mushroom on Leaf (3 points) In this problem Clara appears in a world surrounded by trees (similar to what is shown in Figure 4.1) and she knows that on the first street there is a leaf somewhere. She must find this leaf and then push a mushroom on top of this leaf as shown in Figure 4.2. Figure 4.1. Initial screen Figure 4.2. Final Screen When solving this problem, you can count on the following facts about Clara’s world: • Clara always starts on the first street/avenue facing east • The leaf is always located somewhere on the first street, but never on the first avenue • The mushroom is always located in the same spot (Street 2, Avenue 2). • In order to push the mushroom, it must be approached from behind and any movement forward while being behind the mushroom will result it being pushed forward. Your code must be generic and work with all example worlds supplied with this problem. Practical 5: Variables 5 Bonus Problem If you had previous programming experience – it is advisable to start with the bonus problem and see whether you can complete it. Students who didn’t have prior programming experience should only attempt the bonus problem after completing the regular problems. Problem 5– Pushing Mushroom through Tunnel (10 points) Clara is always on a lookout for new hobbies. Very recently she became a mushroom collector. Her task is to find a single mushroom in the world similar to the one shown in Figure 5.1 and push it so that it is eventually located on top of the leaf as shown in Figure 5.2. In order to push the mushroom, it must be approached from behind and any movement forward while being behind the mushroom will result it being pushed forward. Figure 5.1. Initial Screen This world of Clara has two chambers connected by a tunnel (the tunnel always starts in the middle of both chambers). Clara and the leaf are located in the left chamber. In the right chamber (or inside a tunnel connecting chambers) there is a mushroom. Clara is to get to the other side, find the mushroom then push it into the chamber on the other side. Once on the other side, the mushroom
Apr 24, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here