COMP 110 Summer 2012

Lab 5

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 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 have it draw the basic smiley face.

We want to provide the user a Smiley where they control the appearance. You need to ask the user (using JOptionPane) for the eye color (pick 3), the size of the nose, and if they want the mouth to be a smile or a frown. Be careful about setting the types correctly for each of the inputs! You will prompt the user for each of the inputs inside of 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: In the drawEyes method you might have the line
setEyeColor(canvas, color);
where canvas and color are the arguments passed into drawEyes. Again, be careful with types

Another way to call a method from within its class is to use this as the object.

Example: From drawEyes you would have the line
this.setEyeColor(canvas, color);

Read pp. 257-258.

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