More systems of this kind have been published in the last few years than ever before, and interest in this area is growing. Some Kara exercises are based on material by Horst Gierhardt.Educational programming systems are booming. Note: For an infinite loop, we can press the Run-button.Ĭredits: Ideas and concepts of Kara were developed by Jürg Nievergelt, Werner Hartmann, Raimond Reichert et al. To help yourself, you can draw a flowchart. He is endlessly walking along outside the forest. Note: The Solution should work with pressing on the Act-button only once. You need to figure out how Kara knows if he still has to climb a step or if he’s reached the top. Write a method oneStepUp() to make Kara climb a single step. Kara shall climb arbitrarily long stairs. Kara should then automatically run around the trees until he reached the leaf. Modify act() so that you can just press the act-button once.Test your program in all available worlds. Load the scenario Kara 214… and improve the method goAroundTree() so that Kara can walk around several trees.But now there can be any number of trees in a row. This is a similar exercise as in task 6: Kara must find a leaf that lies ahead of him. Move as long as ther is a tree on the left. In the flow chart you can see that move() is executed repeatedly, as long as no tree stands in front of Kara.ĭescribe what each of the following loops does, and how many steps Kara takes. To execute an instruction block multiple times, loops are used.Īs an example, we want to do the following: But Kara is not yet capable of repeating a specified set of instructions. Kara can now react to rules set by us in different situations. Kara picks up all leaves and stops in front of the trees.Īs a better overview, write some parts of the program in their own methods. Kara plays Pacman: Kara is on the first of a long trail of leaves, ending in front of a tree. You can draw a flowchart as a help to find the solution. Tip: Imagine what must be done each time the Act button is pressed. Load the scenario Kara 211… and write a program for it. One empty field always lays behind Kara which is the field he came from. Each field in the tour has exactly two empty neighboring fields. Kara must find the leaf on this round trip. Load the scenario Kara 210…, write the program and test it. When he reaches the tree he will do nothing (even if the Act-button is pressed again). Kara is running straight ahead and lays a leaf anywhere where there is none. Load the scenario Kara 209… and write the program. Now let Kara go straight and put a leaf anywhere where there is a tree on its left or right or on both sides. Load the scenario Kara 208…, write the program and test it with all three worlds. If so, Kara instantly drops a leaf because of the shock. Kara should check on every field whether it is a tunnel entrance (i.e. This statement would be satisfied (true) if Kara is not facing a tree. Is satisfied (true) if either one or the other or both statements are true.Ĭhanges an expression of true to false and vice versa. if Kara is facing a tree and is on a leaf. Is only satisfied (true) if both statements are true, i.e. The following table shows the three main logical operators in Java: Operator It should also be possible for Kara to react simultaneously to two or more tests. Kara will react differently based on a test. Our Kara can already do more than just execute simple commands. Modify the program so that Kara only picks up the leaf if no tree is on his side.Open the scenario Kara 207… in Greenfoot and write the program as outlined in task Task 5.Your program should work in any of those worlds without error messages. In this scenario, you have several worlds (a, b and c).Program inside the act() method what you have drawn in Task 2 as a flowchart.In this scenario, the method goAroundTree() is already programmed and part of the act() method is prepared. Open the scenario Kara 206… from the folder scenarios-chapter-2.Describe what happens when you run the program.
0 Comments
Leave a Reply. |