COMP 110-003 Fall 2008

Lab 3

25 points

Assigned: Friday, September 12
Due: Friday, September 19 by 2:00pm

Description

Lab 3 will give you some practice with flow charts and if-else statements. You have been given a skeleton program, Smiley.java, that can also be found on the course webpage. Download the file, and compile and run the program in jGRASP. When you run the program you will have to input a String before you will see the program window appear. (You will use this input for part 2.)

Part 1

At the beginning of the program you will notice that there are many named constants. Notice that the identifiers are in ALL_CAPS. Go ahead and change the values of some of the named constants and compile and run the program again to see what changes you have made to the program. Make sure to change the constants back to their original values before continuing to part 2.

Part 2

For this part of the lab you will modify the code in the modifyFace() method in Smiley.java so that is follows the flow chart below.

The flow chart may look daunting so take it one branch at a time. Take a look at the code that has been given to you and notice there are comments in the modifyFace() method that tell you where you should put your code. You will not have to change any code before the comments or after them. I have already given you code that reads in the initial user input (as a String) from the keyboard, so all you need to do is write the multibranch (nested) if/else statements. Also, the only existing variables you will need to change the values of are eyeColor, noseDiameter, xNose, and mouthStartAngle (although you will probably have to make some of your own variables too). Do not worry about error checking. If the user inputs the incorrect thing, the original smiley will display without any changes.

To change the eye color, you can use a statement like this:

    eyeColor = Color.RED;

You can find a list of predefined colors in your textbook on p. 202 (4th edition) or p. 165 (5th edition).

When the diameter of the nose is increased, if you don’t adjust the position of the nose on the x-axis, the nose will move to one side of the face. Thus, you need to adjust xNose accordingly when you change noseDiameter.

I recommend you start with MOUTH because it is the easiest case.

Write comments in your code as necessary. Imagine that someone who does not know the purpose of your code in the modifyFace() method is reading your code. How would you explain to them (in English) why your code is doing what it is doing? Use this explanation as comments in your code. Comments should not be used to restate the obvious, but to enhance understanding.

Grading

How to turn in the assignment