![]() |
Lab 8
|
|
Run the method boo above by hand, to compute the following:
Note that integer division in Java yields integers, so, for example
[10/3
is 3
(not
3.33
) and 5/3
is 1
(not 1.66
)].
Recall from the lecture on fruitful recursion,
the stepsToWall() fruitful method that you studied. Here is that definition,
again:
|
Study the following method definitions for solving the same problem, i.e. counting the steps to wall. Which ones do you think would work, and which would not? Feel free to work with a friend on this one!
|
|
|
|
Look in the HungryWorld folder inside lab7_programs.
Harry is a hungry, but very eccentric buggle. He always starts
out in the middle of the first row of a grid facing NORTH
with his brush up (can you hear his stomach
rumbling?). The grid cells are randomly populated with a
user-specified number of bagels, but no bagels are in the column
Harry starts out in. The buggle moves row by row from the bottom
to the top, and performs the following action at each row:
|
|
Your solution must several methods to take care of the several sub-tasks in this problem. Note that it may be easiest to define these methods in the reverse order than that given in order to test each method one at a time.
Here are the method headers for the methods I used in my solution:public void eatAllRows();
This method applies theeatOneRow()
method as the buggle works her way from the bottom row to the top-most one.
public void eatOneRow();
This method implements the row-eating behavior as described above, for one row.
public int countBagelsAhead();
This method counts the bagels ahead of the buggle (which is located in the middle of the rwo) and until the wall. Calling this method should not change the state of the buggle.
public void eatBagelsAhead();
This method implements the bagel-eating behavor of this kind of buggle: Eat the bagels ahead of the buggle, and leave a red square where a buglle used to be.
Look in the Patchwork
folder inside the lab8_programs
you downloaded. We're going to
draw some interesting patterns. Have a look at the behavior of the
program in the Test subfolder, by running the file Patchwork.html
in your browser. Your job is to modify the
code in Patchwork.java to duplicate this behavior you see in this applet. Be sure
your code works for zero levels.
Be careful! The code can be very simple, but the pattern is diabolical! Getting the colors to come out right is a bit tricky.