AP Computer Science A

Karel J. Robot Lab #2

Objective:  

This lab explores a central idea in Object Oriented Programming.  You will look at extending classes to build specific functionality.  You will created methods and look at:

Pair Programming:

Problem #1:  

Implement your solution to the harvester problem.  Once you have a working solution, open the solution package and see an alternative method of solution.

Individual Problem Statements:

Problem #1:

Karel sometimes works as a pin-setter in a bowling alley.  Write a program that instructs karel to transform the initial situation (a beeperless world) into the final situation (shown below).  


Problem #2:

The figure below represents a baseball field of beepers. Write a program that places the beepers in a diamond shape.  Hint:  You should be able to use some of the code you created for problem #1.  

Problem #3:

Create a program that spells HELLO as shown below.  (Hint:  More than one robot may be needed).  Note, you will need to create the classes from scratch.  Use the structure given in problems 1 and 2.


Problem #4:

Write a program where the numbers, 3, 2 and 1 are displayed in beepers.  These should look like a countdown (i.e. the 3 appears, is removed, the 2 appears, is removed, the 1 appears and then is removed).

Take your time setting up your classes and think about our Harvester vs. Planter classes from before.

**These numbers should disappear before the next number is written**

Question #1:

Suppose we define a method in a robot class like this.

public void move()

{

        super.move();

        move();

}

What will happen if we send our robot such a method?  If you want to test this, start your robot facing West or South.  What is the meaning of the move instruction within this method?