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 problem in part A. Your group should have the following roles:
You will not always play these roles. During general discussion, everyone participates.
A. Maze Escape
Driver: Download this project and unzip it
somewhere. Be sure it is actually extracted. By default, Windows only gives
you the illusion of extracting it. Start NetBeans. In NetBeans, select
File->Open Project and select the extracted robot1
directory. Run the project to make sure that it works. If it doesn't, ask
the instructor or lab assistant for help.
Everyone: Read the problem description below and the javadoc of the Robot class.
Carol the robot was imprisoned by the sinister Cardinal Mazerin, and now she must escape. Fortunately, she remembers the “right hand rule” for getting out of a maze: Always keep your right hand on a wall, and eventually you will reach the exit. (This rule works, provided all parts of the wall are connected.)
In order to help Carol escape, her faithful servant, the hunchback Quaternion, dropped a beeper just outside the entrance.
public void step()
The program calls the step method in the following
pattern:
while (!carol.isOverBeeper()){
step(); // YOU are implementing this method
if (!carol.rightHasWall())
{
carol.say("Whoa! There isn't a wall to the right any more!");
}
}
Here, ! is the “not” operator: While Carol is
not over a beeper, call the step method.
Your step method should enforce the "Right Hand on Wall"
strategy. At the end of the step method, the robot should have
a wall to the right or be over a beeper. That way, the robot will go from
one "Right Hand on Wall" position to the next "Right Hand on Wall"
position, until it reaches the beeper. Keep in mind that the robot should
always have a wall to the right or be over a beeper when the
step method returns.
Oh, and it is important that, when the step method returns,
the robot should either be on top of a beeper or have a wall to the right.
Did I mention that? Just checking, because the first time I gave this lab,
most students ignored this and had poor Carol run all over the place.
Discuss as a group how this problem can be solved. Be sure only to use the methods of the Robot class, not any general intuition that you may have. What moves and turns does the robot make in which situations? You will probably find it helpful to consider different cases such as the following:

Keep in mind that the robot should always have a wall to the
right or a beeper below when the step method returns.
Simulator: Write up on a sheet of paper what you agreed upon, using
pseudocode, i.e. a mixture of English and Java code. Your step
method should have several "if" clauses.
Director: Draw this pattern on a sheet of paper and obtain a token for the robot—something with a direction such as a paper clip.
Everybody: Review your group's pseudocode and check that it reflects your understanding of the discussion.
step method. The director reads off the next
statement. If it involves Carol, the director tells the simulator what
Carol should do, such as "move forward" or "is there a wall in front?"
(Remember, no peeking by the director.) The simulator moves the robot token
and answers any questions ("no wall in front").
After a statement has been executed, move on to the next. At the end of
the step method, go back to the beginning, except if
the robot is on a beeper.
If you find any mistakes in the pseudocode, stop the simulation and as a group discuss how the pseudocode needs to be improved.
As the simulation progresses, the driver translates the pseudocode
instructions into Java and enters them into the step method of
the MyScene class, under the line marked // Your work
here
Disband your group of four and work together as a group of two to solve the programming problem in parts B, C and D.
B. Vowels
isVowel method in this class that
should return true if letter consists of a single
letter that is a vowel. What is your method?main method in WordTester.java. Did all tests pass? If
not, what did you need to do to fix your isVowel method.isVowel method. Inexperienced programmers
commonly write code of the form
if (some condition) return true; else if (some other condition) return true; else return false;
when instead they could simply write
return some condition || some other condition;
Can you rewrite your solution using a single return
statement? If so, give your code. If not, explain.
isVowel without any
if statement. Hint: Look at the API documentation of the
String class and the contains method. What is
your implementation of isVowel using this method? if
statements or the one with contains? Why?C. Patterns
public boolean fill(int row, int column)
{
return your expression here;
}
for each row and column between 0 and 9, filling in squares when the
method returns true.
Your task is to implement the fill method in various ways
in order to generate different patterns. For example, if your
fill method is
public boolean fill(int row, int column)
{
return !(row == 0 && column == 0);
}
then all squares are filled in except the one at (0,0).

In the following exercises, you will be asked to generate various patterns. First write the Boolean expression on a sheet of paper. Driver and scribe take turns for each of the patterns. Then discuss whether your expression is correct. Finally, the driver types in the expression in the program, compiles, and runs. The scribe types in the expression in the report.
Your goal should be to get the correct result in one try. If you find yourself making random changes on the computer, take your hands off the keyboard and start thinking again!
Some of the patterns depend on whether the row or column are even or
odd. Remember that n % 2 == 0 is true whenever the integer
n is even.
What is the expression that makes this picture? (Driver)








D. The Genetic Code
Your task is to
complete the methods isLeu and isIle in this class. As in the preceding assignment, your
methods should compute and return a single Boolean expression, like
this:
public boolean isPhe()
{
return bases.startsWith("UU") && "UC".contains(bases.substring(2));
}
What is the code for your methods?