Smiley Faces

Lab Assignment 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.


Pair Programming

You are required to pair program for this assignment.


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 fully test all the public SmileyFace methods and with drawing one, two and three faces.

The program's 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.

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


Getting Started

Obtain the workspace: Be sure that you have downloaded the ICS 45J 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.

Download the project, and integrate it into the workspace:

  1. Download the Lab 1 Eclipse project, Lab1.zip.
  2. Unzip it, producing a folder called 45JLab1.
  3. Move the Lab1 folder that’s inside 45JLab1 into the folder containing your Eclipse workspace. For example, if your workspace is in H:\45JWorkspace, you’d want to move the Lab1 folder into H:\45JWorkspace.
  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.)

Code it up: 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.


Code We've Provided (and that You Provide)

For this first, introductory assignment, we've provided the "high level" design for you, having figured out the classes we should have and their public methods. Do not change these classes definitions or the signatures of these methods— other parts of the program (like the graphics routines and other code wriitten, or to be written, by others) may well depend upon these definitions, and changing them could break the program. However, you are free to, and should, provide any required or useful private components (fields, methods, constants, whatever) to have the program meet all its requirements and exhibit good style.

We have also provided, through object files (in the lib folder) the graphics routines needed to draw smiley faces in the graphics window. The main() method calls another method that calls these routines after the smiley group has been built. So for this assignment, there is no need to worry about drawing the smileys; that happens "automatically" though code we've provided.

As we progress through the assignments, more and more of the high-level (and detailed) design of the program will be left up to you: programming includes many skills beyond just implementing method bodies!


Keeping In-Program Documentation Accurate

In the provided code are lots of comments describing what the parts of the program do (or should do, once you've completed them) and what code you are to provide. As you work on your program, be sure to modify the comments as needed to reflect a completed program (and, of course, to add your own, additional ones as needed). For example, there are some comments in some classes that say what fields you need to have. Once you have provided the code for those fields, that comment no longer applies and should be removed; instead, you should have brief comments describing what each field holds.

We require you to do this as a matter of course in all assignments from here on out, so we won't specifically mention this in subsequent assignment write-ups.


Deliverables

Have your progam display three distinct (non-overlapping) smiley faces, each with 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. Call each of the public methods in SmileyFace and SmileyFacePart at least once. (The SmileyFacePart calls are made indirectly via calls to methods inherited by the Eye, Face and Mouth classes.)

Zip up your workspace folder into the file SmileyFaces.zip, and turn it in via Checkmate.


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.
Revised for use in ICS45J, by Norman Jacobson, August 2012.
Deliverables section revised, by Norman Jacobson, October 2012.