ICS 21 / CSE 21 Summer 2012
Lab 1: Smiley Faces


Purpose

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 required 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 will also need to implement methods that translate (i.e., move) smiley faces as a whole, and that let you scale and translate each of the smiley's parts (the face, eyes and mouth).

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

Program behavior is straight-forward: when run, a graphics window appears. It creates a SmileyGroup automatically, then draws the smiley faces described by that SmileyGroup. Once you've finished the program, you should see one, two, or three smiley faces, each with a face, 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

First of all, if you haven't already, be sure that you download the ICS 21 / CSE 21 Eclipse workspace. (Details about how to set it up are available in the orientation lab that you did previously.) Many settings have been changed from their defaults to appropriately support your work in this course, and you should be sure that you're working in an environment that matches as closely as possible the environment that you'll be using during lab exams.

Next, you'll want to download an Eclipse project that I've set up for you and import it into your workspace. Follow these instructions to get yourself set up.

  1. Download the Lab 1 Eclipse project.
  2. Unzip it, producing a folder called Lab1.
  3. Move the Lab1 folder into the folder containing your Eclipse workspace. For example, if your workspace is in F:\21Workspace, you'd want to move the Lab1 folder into F:\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 six warnings — each of these warnings indicates that there is some part of the program that have yet to be written. (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 whatever part of the program you're working on. Eclipse is aggressive about noting issues as they come up, which can seem disconcerting at first, but you will come to find them invaluable as you become more used to them.

You should always follow good design strategies in your code. We help you do that with this assignment by showing you the classes and methods that you should have (and where they should be defined and used). Note especially how heavily we rely on using many classes and methods and how little of the work is done in the program's main() method. As the assignments progress, you will be expected to complete gradually more of the design yourself.

When writing any program, you should follow a good, consistent coding and documentation style. Clearly name your classes, methods, fields, and variables; consistently indent your code. The code that we provide and the code that you see in Horstmann's text should provide a strong guide.


About Lab Exam 1

Lab Exam 1 will be very similar, but perhaps not identical, to the program you are building for this exercise. In particular, the program allows you the freedom to explore different combinations of smiley faces and their attributes; the lab exam may ask you for something more specific.

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