Copyright © Cay S. Horstmann 2009 
This work is licensed under a Creative Commons
Attribution-Noncommercial-Share Alike 3.0 United States License.
Work together as a group of four to solve the programming problems in parts A through C. Your group should have the following roles:
You will not always play these roles. During general discussion, everyone participates.
Part A. Counting Syllables
Driver: Make a page with the title "Lab 8 name1 (Facilitator), name2 (Simulator), name3 (Director), your name (Driver). Use first and last names.
countVowels method in this class that
counts the number of vowels in a word. Use the isVowel method
to test whether a character is a vowel.
As a group, decide on a strategy.
Simulator: Write up on a sheet of paper what you agreed upon, using pseudocode, i.e. a mixture of English and Java code, then give it to the director.
Driver: Make a sheet for tracing variables i, letter, and count, and give it to the simulator.
countVowels method. The director reads off
the next statement. If it involves updating a variable, the director tells
the simulator what to do, such as “add 1 to i” or “set ch
to the character with index 0”. If the director needs to know a
variable's value, ask the simulator! (Remember, no peeking by the director.
Everyone else should peek.) The simulator reveals and updates any
variables.
After a statement has been executed, move on to the next, until the loop ends.
For this simulation, assume that the text instance variable
has been initialized with the string "beauty".
In this particular simulation, we will assume that the
isVowel method works correctly. You need not trace inside it.
Word class, using BlueJ. Run this WordTester1 class. Did it
pass the tests?
Simulator: While the driver is entering code, enter the pseudocode into the lab report.
If not, discuss as a group what went wrong.
Driver: Paste the code for the working countVowels method into the Google group.
As a group, decide on a strategy.
Simulator: Write up on a sheet of paper what you agreed upon, using pseudocode, i.e. a mixture of English and Java code, then give it to the director.
Everyone: Review the pseudocode to see that it reflects your group's intent.
Driver: Make a sheet for tracing any variables used in your pseudocode and give it to the simulator.
If you find any mistakes in the pseudocode, stop the simulation and as a group discuss how the pseudocode needs to be improved.
Facilitator: Be prepared to report whether your group succeeded, what strategy you used in your algorithm, and what you learned from this exercise.
WordTester2 class. Did it pass the tests? If not, discuss
as a group what went wrong and find a fix for your error.
Simulator: While the driver is entering code, enter the pseudocode into the lab report.
Driver: Give the code for the working countVowels method to the simulator for inclusion in the lab report.
B. Drawing a Spiral

I really mean everyone should draw the spiral. I want your brain and your fingers to connect...
dropBeeper method before
every moveForward so that the beepers trace her path.

Note that the length of the spiral arms follow a definite pattern.
Find that pattern, then develop a strategy as a group. You
will want to review the API of the
Robot class to remind yourselves what a robot can do.
Simulator: Write up on a sheet of paper what you agreed upon, using pseudocode, i.e. a mixture of English and Java code, then give it to the director.
Everyone: Review the pseudocode to see that it reflects your group's intent.
Driver: Make a sheet for tracing any variables used in your pseudocode and give it to the simulator.
If you find any mistakes in the pseudocode, stop the simulation and as a group discuss how the pseudocode needs to be improved. (Note: A common mistake is to make the spiral too tight, so that the beepers simply fill the entire surface. Look at the picture above and notice how Carol drops two beepers for every square in the graph paper.)
Facilitator: Be prepared to report whether your group succeeded, what strategy you used in your algorithm, and what you learned from this exercise.
run method of the
MyScene class. Run the code. Does it produce the spiral
pattern? If not, what fixes did you make?
Simulator: While the driver is entering code, enter the pseudocode into the lab report.
Driver: Give your code to the simulator for pasting into the lab report.
C. Drawing the spiral with Line2D.Double
SpiralViewer and SpiralComponent classes to get
you started. As a group, look at the code that is provided. Develop an
algorithm for drawing the spiral. This is not as easy as with the robot
because (a) there is no obvious way of "turning" a point or line and (b)
you need to compute the start and end points yourself. Actually, you only
need to compute the end point because the start point is always the end
point of the previous line.
You will need to develop the math for locating a point that is above,
below, to the left, or the right of a given point. That is a good way to
get started. Given the point (100, 100), how do you find the point above,
below, to the left, to the right, at distance 10? At an arbitrary distance?
What if it is an arbitrary point p? (Hint:
p.getX(), p.getY().)
You should draw 40 segments of the spiral. There are two strategies. You
might write a loop that is executed 40 times, calling g2.draw(new
Line2D.Double(start, end)) once per iteration. Or you might execute
a loop ten times, drawing four segments per iteration.
Discuss the advantages and disadvantages of each approach and make a choice.
Keep in mind that the segments need to be long enough to be visible. Use a grid size of 10 pixels. That is, the first segment should be 10 pixels long. Start at (100, 100).
Simulator: Write up the pseudocode on a sheet of paper.
Everyone: Review the pseudocode to see that it reflects your group's intent.
Driver: Make a sheet for tracing any variables used in your pseudocode and give it to the simulator.
The simulator needs a sheet of graph paper.
The director places a marker (such as a coin or paperclip) next to the currently executed statement on the pseudocode sheet. The director reads off the next statement. The director tells the simulator to draw line segments, for example "Draw a line from (100, 100) to (100, 90)". If any variables need to be updated, the director tells the simulator what to do, such as “add 1 to n”. If the director needs to know a variable's value, ask the simulator! (Remember, no peeking by the director. Everyone else should peek.) The simulator reveals and updates any variables.
If you find any mistakes in the pseudocode, stop the simulation and as a group discuss how the pseudocode needs to be improved.
You don't need to simulate all 40 segments. Stop when you are confident that your algorithm is right.
Facilitator: Be prepared to report whether your group succeeded, what strategy you used in your algorithm, and what you learned from this exercise.
paintComponent method of the SpiralComponent
class. Run the code. Does it produce the spiral pattern? If not, what fixes
did you make?
Simulator: While the driver is entering code, enter the pseudocode into the lab report.
Driver: Paste your code into the lab report.