Karel starts in the world on the left. How would you program Karel to pick up the beeper and transport it to the top of the ledge? Karel should drop the beeper at the corner of 2nd Street and 4th Avenue and then continue one more corner to the east, ending up on 5th Avenue. At the end of your program, Karel's world should look like the picture on the right.


If Karel only knows the commands:

move()
pickBeeper()
putBeeper()
turnLeft()
How can you make Karel turn to the right?

Solution

A solution is provided for this example, so that you can see what a full program looks like!

/**
 * Program: Step Up
 * ----------------
 * Your first example Karel program. Have Karel pick up the beeper infront
 * of her and place it on top of the ledge.
 * This is a comment. Your computer will ignore it.
 */
public class StepUp extends Karel {
	
	// When you start your program, this code will be executed.
	public void run() {
		move();
		pickBeeper();
		turnLeft();
		move();
		turnRight();
		move();
		putBeeper();
		move();
	}

	// Defines a new command called turnRight
	private void turnRight() {
        turnLeft();
        turnLeft();
        turnLeft();
    }
}