Smiley Faces

Lab Assignment 1
to prepare for Lab Exam 1

This lab assignment gives you some practice in basic Java programming by asking you to implement the “smiley faces” example we’ve been discussing in class — with a few additional wrinkles.


Program Behavior and General Requirements

In general, you are to write a Java program that draws one, two or three smiley faces on the screen, each with characteristics you provide, such as the color and the shape of the face itself, and of the eyes and mouth. You also implement methods that translate (move) the smiley as a whole, and that let you scale and translate each of the smiley’s parts (the face, eyes and mouth). (Scaling the smiley face as a whole requires some knowledge of linear algebra, so we do not include that feature.)

The SmileyGroup() constructor contains the code that produces the faces. We suggest you write various bodies for SmileyGroup() so that you gain experience in using the two smiley face constructors, the setAttributes() method and the smiley face translation and scaling routines, and with drawing one, two and three faces.

Program behavior is straight-forward: when run, a graphics window and SmileyGroup are created, then SmileyGroup is given to the graphics routines, which draws the one, two or three smiley faces described by that SmileyGroup; the window is then made visible on the screen so that the user actually sees the smiley group. This approach, common in graphics environments, allows the programmer to fully construct a screen before showing it to the user.

Each face you make should have two eyes that are above an imaginary horizontal line through the center of the face, and a mouth that is below that imaginary line; the eyes and mouth should have colors that make them distinguishable from the face. Within these parameters, you may make the faces look however you'd like.

The user clicks on the close box to close the window and stop the program.


Getting Started

Be sure that you have downloaded the ICS 21 Eclipse workspace, and have set it up as described in the Orientation to the Lab section of this manual. Many settings have been changed from Eclipse defaults to appropriately support your work in this course, so be sure that you’re using this workspace. That way, not only will things be properly set up for your assignments, but your work will match the environment that you’ll be using during lab exams.

Download the Eclipse project for this assignment and import it into your workspace:

  1. Download the Lab 1 Eclipse project, 21Lab1.zip.
  2. Unzip it, producing a folder called 21Lab1.
  3. Move the Lab1 folder that’s inside 21Lab1 into the folder containing your Eclipse workspace. For example, if your workspace is in H:\21Workspace, you’d want to move the Lab1 folder into H:\21Workspace.
  4. Start up Eclipse and select your workspace.
  5. From the File menu, select Import..., which will pop up a dialog box. Under General, select Existing Projects into Workspace, then click Next >.
  6. Next to Select root directory, click the Browse... button. Find the Lab1 folder that you copied into your workspace folder, select it, then click OK.
  7. Finally, click Finish. You should now see a project called Lab1 in Package Explorer. Your Problems window should show some warnings; each of these warnings indicates that there is a part of the program that has yet to be built. (Not all warnings indicate this, but these warnings do.)

As you work, Eclipse will compile your program automatically each time you save it. Pay attention to changes in the Problems window, especially errors, because these often indicate things that you’ve either done incorrectly or things that you need to do to finish the part of the program you’re working on.


About Lab Exam 1

Lab exam 1 will be similar, but not identical, to the program you are to code for this exercise. In particular, the assignment allows you the freedom to explore different combinations of smiley faces and their attributes; the lab exam instead will be quite specific about the characteristics of the faces you are to draw. Remeber to read INSTRUCTIONS!.txt and program comments before beginning your coding; they will explain in detail what is required. Remember that you must follow the exam specifications completely to pass the exam and that a significant failure to follow class style standards can result in a “not pass” even if your program is otherwise complete and correct.

The lab exam will have you code one or more of the following methods:


Written by Norman Jacobson for ICS 21 Fall 2006, September 2006.
  Some text, especially in Technical Details, taken or adpated from the
  August 2004 version of "Reporting Test Statistics," a previous ICS21 exercise.
Minor edits for clarity, by Norman Jacobson, December 2006 and September 2008.
Revised to reflect use of Eclipse, addition of the SmileyFacePart copy constructor,
  by Norman Jacobson, September 2009.
  Includes some text adapted from Alex Thornton's "Lab 1" for ICS 21 Summer 2009.
Minor editing by Norman Jacobson, September 2010.
Revised to reflect computeUpperLeft()'s move to the graphics module, and other minor editing by Norman Jacobson, December 2010.