ch7_hw
ch7_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?)
// 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()