You are on page 1of 5

Stepwise Refinement

Chapter 3, Section 3.1 pages 42-52


Make a plan for Mark to harvest the field.

Name

Period

Stepwise Refinement KEY


Chapter 3, Section 3.1 pages 42-52
Make a plan for Mark to harvest the field.
Comments for Main
Method
//move to start

Details

Methods

move

//harvest pair 1

harvestCorner*,
move
harvestCorner,
move
harvestCorner,
move
harvestCorner,
move
harvestCorner
turnLeft, move,
turnLeft
See above
turnRight**, move
turnRight
Repeat for pairs 2
and 3
Move forward
When done, turn of

1) move()
2) harvestTwoRows()
a) harvestOneRow()

// position for next pair


//harvest pair 2
// position for next pair
//harvest pair 3
//move
//turn of

b) goToNextRow()
c) harvestOneRow()
3) positionForNextHarvest()

4) move ()
5) turnof()

Notes:
* harvestCorner is only pickBeeper(). By creating a method, the program can
be easily modified in the future if a field with two or more beepers at each
corner needs to be harvested.
**turnRight() is turnLeft() 3 times
New methods within larger methods are private, but making them public
would work here, too. When a program has more than one class, public
methods can be used by other classes. Private methods can be used only
within their class.

Constructor

New Methods

Main Method and World

Modifications
1. Create new worlds:
a. harvestLongerRows: Place more than 5 beepers in each row.
b. harvestMoreRows: Add more rows of beepersbe sure to have an even number of
rows.
c. harvestMoreBeepers: Add more beepers to each corner. Be sure each corner has
the same number of beepers.
d. No world, just add this:World.setSize (15,15) (or whatever size you want). Instead
of harvesting beepers, plant them.
2. Copy your projects (one for each world)
3. Modify your methods and main methods to accommodate the new worlds.

You might also like