COMP 110-003 Spring 2013

Lab 5

25 points

Assigned: Thursday, February 28
Due: Sunday, March 24

Description

Lab 5 will revisit the happy smiley face from lab 3, but this time we will write a Class with methods. You have been given a skeleton program SmileyClass.java that can be found on the course webpage. To run the program you also need SmileyMain.java. Copy both programs into Eclipse (create a new Java Project with 2 Java Class files in it - one for each of the above java files). When you have SmileyMain.java selected in Eclipse, run the program (it won't do much yet).

You have been given the class SmileyClass.java with empty methods. You will need to write all the code to fill in the empty methods based on the code you wrote in lab 3. Your methods should perform the actions described in the comments above each method. You have been given the completed method drawFace which will draw the base circle of the face.

You should start by adding the drawing features to the draw methods by finding the corresponding code in lab three and pasting the correct code into the correct method. Once you have added the drawing code you should be able to run the program and draw the basic smiley face.

We want to provide the user a Smiley where they control the appearance. (Using JOptionPane) You need to ask the user for the eye color (pick 3), the size of the nose, and if they want the Smiley to smile or frown. Be careful about the types each method calls! You will prompt the user for each of the inputs in SmileyMain.java. (Unlike Lab 3, this time you will prompt the user for modifications to all 3 components, eyes, nose and mouth). You do not need to declare or initialize any variables because it has already been done for you.

You now need to fill in the remaining methods in SmileyClass. Notice that some of the draw methods will need to call private methods (look at the comment descriptions above each method). These private methods are called by methods within the SmileyClass and cannot be called from SmileyMain.java. To call a private method you call the method without the object.
Example: From drawMouth() you would have the line
setMouth(smile)
where smile is the argument passed into drawMouth and holds the boolean variable you will use to decide the value for mouthStartAngle variable. Again, be careful with types

Another way to call a method from within its class is to use this as the object.
Example: From drawMouth() you would have the line
this.setMouth(smile)

Here is example out (and user input) for the program:
What eye color would you like? (blue, green, or cyan)
green
How big would you like the nose?
3
Would you like the smiley to smile? (true, false)
false

Additional Instructions

Grading

How to hand in the assignment