Informatics 1 WS 2019

Website of Prof. Dr. Barne Kleinen, Professor for Media Informatics (Bachelor/Master) at HTW Berlin

Exercise 01: Programming Kara

     next>

Pre-Lab

  1. Download the Scenarios and read through the Kara programming exercises in the assignment.

  2. Write down how Kara could solve the task for each one of them. For example, if the programming exercise was Exercise 4 from Worksheet 1, where Kara was to move in a Square and drop a leaf in each corner, you could write down something as this:

    1.  walk one edge (call move n times),
    2.  drop a leaf
    3.  turn right
    4.  repeat 4 times from step 1
    
  3. Make use of Greenfoots act()-loop - split the problem into repeating steps, and the position that Kara should be in after this step. In the example above, each call to the act() method should make kara walk one side, having her face in the direction of the next side at the end of each step.

  4. When designing the algorithms, think of useful methods that help you/make your tasks easier and name them/use them in your algorithm description.

Assignment

Download the scenarios for these exercises if you haven’t already done so for the prelab. It contains a KaraWorld and a Kara (named Kara01-Kara07) for each programming task. Solve all Programming Exercises using the according scenarios, and upload the all scenarios as a zip file.

Hints

For all problems, make sure to extract methods where appropriate to make the source code more readable.

Most of the problems here are extensions of problems we’ve already solved in class. So it’s usually a good idea to first identify a similar problem we’ve done in class and modify the solution we did there. So get out your Worksheet 2 and compare! Here’s a link to the scenarios we did in class.

1. Count leaves laid

(lab01_kara01): Using an integer variable, make Kara lay down 10 leaves in the middle lane.

Scenario after program was run
10 Leaves

2. Kara in the Tunnel

(lab01_kara02): Kara is afraid of Tunnels. When entering the tunnel, Kara is scared and drops one leaf; then she walks through the tunnel (without dropping further leaves) and immediately stops after leaving the tunnel. Note that “in the tunnel” means that there is a tree on both sides, not just on one. Provide a general solution and Test it with both Worlds in the scenario.

StartStart
EndEnd

3. Leaves in the forest I

(lab01_kara03): Building on Exercise 7 of Worksheet 1, where Kara looks for a leaf in front of him, modify the algorithm to make her able to walk around 2 or more trees in a row.

Scenario
Forest

4. Leaves in the forest II

(lab01_kara04): In this forest, each field has exactly two neighboring free fields, one of them behind Kara, and the other one either to the left, in front or on the right. Make Kara move through the forest and find the leaf.

Scenario
Forest

5. Picture Inversion

(lab01_kara05) Program Kara such that it will create an “inverse picture” within a tree rectangle. E.g. starting as in KaraWorld05, as in the first picture, the picture should look like the second picture after the program has run.

BeforeAfter
StartEnd

Start Image End Image

6. Draw a Spiral

(lab01_kara06) Draw a Spiral like the one shown in the picture. spiral

7. (for the bored:) Make Kara add two numbers in binary format.

For the bored exercises are optional! In lab01_kara07 the world creates two random 8-bit binary numbers, a leaf means 1, no leaf means 0. Make Kara add them up using place value and carrying, which is basically the same as adding up decimal numbers using place value and carrying. Here’s an explanation how to do it for binary numbers.

ResultStart Image

Result Result

Post-Lab, AKA What to Turn In

Please upload 2 Files to Moodle:

  1. A PDF with your Lab Report, containing your answers to the Pre-Lab. You can order them as you like, e.g. combine the algorithm sketched in the prelab with the algorithm that actually worked in the lab rather than having a section “prelab” and “lab report”.
  2. The Scenario with your solutions in each Kara’s act method as a ZIP file.

Read the info on the Lab Index page again if you’re unsure about the nature of the lab reports - or simply ask!