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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |