Graphic by Keith Ohlfs

CS111, Wellesley College, Fall 1997

Lab #8
[CS111 Home Page] [Syllabus] [Students] [Lecture Notes] [Assignments] [Programs] [Documentation] [Software Installation] [FAQ] [CS Dept.] [CWIS]

CS111 Lab #8: More Recursion

You do not need to turn in this lab.

1. Low Hurdles Revisited.

In Lab 7 you wrote a class for a low hurdler buggle, that would run hurdles until it reached a wall of two stories in height or more. We will examine two types of solutions (given in the Buggles folder), and discuss the differences between the two.

2. Retrieve World.

In lecture, you were introduced to a retriever buggle, who would move forward until it came to a bagel or a wall. If it found a bagel, it would pick it up and return to the starting position and then drop it. If it hit a wall it would simply return to the starting position. In one version, the retrieve method returned a value of true if a bagel was found and a value of false if no bagel was found.

We will modify this class so that the retrieve method will return an integer equal to the number of steps the buggle took to reach the bagel. It will return a negative number (e.g. -1) if it reaches a wall.

3. Bagel Trees.

In this exercise you will get more practice writing recursive methods. The object is to write a method to draw a tree of bagels. The tree is specified by two parameters: size and height. The size refers to the length of the branches in the initial level of the tree. With each successive level, the branch size decreases by half. The height refers to how many levels of the tree are to be drawn. The following images show some examples of Bagel Trees (BagelTree(height, size))

BagelTree(1,4):

BagelTree(2,4):

BagelTree(3,4):

BagelTree(4,8):

In the BagelTreeLab.java file, you are given the skeleton of tree(height, size) that you should modify to draw the BagelTree. You are also given 4 methods that draw the left and right branches of each level. You need to write the tree method so that it draws the bagel tree recursively. Think carefully about the base cases and about where to make the recursive call to tree.

You do not need to turn in this lab.