0% found this document useful (0 votes)
6 views3 pages

ch7_hw

The document outlines three programming tasks for a robot named Karel, each requiring the implementation of a specific class with a public method. The tasks involve carpeting a hallway, retrieving a beeper from the west wall using recursion, and moving a line of beepers north without using instance variables. Each class must be created within the same BlueJ project folder and adhere to the specified requirements.

Uploaded by

Abduln
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

ch7_hw

The document outlines three programming tasks for a robot named Karel, each requiring the implementation of a specific class with a public method. The tasks involve carpeting a hallway, retrieving a beeper from the west wall using recursion, and moving a line of beepers north without using instance variables. Each class must be created within the same BlueJ project folder and adhere to the specified requirements.

Uploaded by

Abduln
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name ____________________________ Period _____

Karel J Robot - Chapter 7 HW

There is a world file for you called recursion.wld. Please have the 3 classes for these 3 problems
located in the same BlueJ project folder.

Karpeter Lab

1. Karel is carpeting hallways again. The hallways always have the same general shape as below
and are always one block wide. To make sure there are no lumps in the carpet, only one beeper can
be placed on a corner. There are no beepers in the hallways to begin. Karel has enough beepers to
complete the job(passing ‘infinity’ as the parameter will take care of that) and always starts in the
same relative location. Karel should finish where she started. Name your class Karpeter. You
should have one public method with the heading: public int carpetHallway() {…}

In addition to carpeting the hallway, the Karpeter class should also be able to return a number
representing how many beepers were dropped to carpet the hallway. (extra challenge: accomplish this
without the use of any instance variables!! doesn’t seem possible, does it?)

some possible starting


positions – karel will
always start facing down a
hallway, as to want to move
around in a clock-wise
manner
2. Program a robot named Karel to pick up a beeper at the west wall and return to the corner on which
she started. There may be other beepers in the path(which should be ignored), but it is known that
there is a beeper on 1st avenue directly west of Karel’s starting position. Originally, you do not know
which way Karel is facing. You must use recursion – no iteration. You may not use instance variables
(no counting so you know how far to return – recursion counts for you!).
Name your class WestWallBeeperGetter. Your one public method should be called
getBeeper().
3. Karel is facing east. In front of her, somewhere along the street she is on, is a line of beepers (one
beeper is on each corner, with at least one beeper in the line). The length of the line of beepers is
unknown, but there are no gaps in the line. Karel must pick up and move the beepers north a number
of streets equal to the number of beepers in the line. For example, if Karel started off at the origin and
there are 5 beepers in the line, the beepers must be moved to 6th street. The beepers must be moved
directly north. If the first beeper is on 4th avenue, it must be on 4th avenue when the program is
finished; karel should not be standing on a beeper when finished. You may not use any instance
variables. Name your class BeeperMover – name your one public method
moveBeepersNorth().

// client/driver code
BeeperMover angela = new BeeperMover(2, 8, East, 0, Color.red);
angela.moveBeepersNorth();

Here is some sample code that you might put in your moveBeepersNorth method – this might help
you design your class:

findStart();
pickAndTranslateSelfToTheNorth();
dropRow(); // when writing dropRow, it might be helpful to write a helper method called putBeepers()

here is the world you’ll use


for all three labs

Again, you have one main


which will create 3 different
types of bots and have them
do the 3 labs. Each bot
should be a different color.

karel might start here


facing west (lab 2)

karel might start here


karel might start here
facing east (lab 3)
facing north(lab 1)

You might also like