CS100A Fall 1998 Assignment 2 Due at beginning of lecture on Tuesday, 22 September

Table of Contents

0. Working with others. In general, when working on an assignment that requires working on the computer, you may discuss the assignment with others and ask questions of anyone about details of using the computer, etc. You should not copy someone's work, either electronically or by hand, and you should not hand in work that is not yours.

For this assignment, you may work with one other person. If you work with someone else, then you must actually do the work together --sit at a computer together and make changes together. It is not proper for one person to do the work and then to add someone else's name to it. If you work with someone else, then hand in only one assignment; put both person's name and id on it.

1. Finding this assignment on the web. This assignment can be found on the world wide web. Go to the web site for computer science, http://www.cs.cornell.edu, and browse until you find the site for CS100A and then for this handout (e.g. click on "Course Home Pages"). On the web, you may see this handout in living color and use it as a hypertext document. You will need two files for this assignment: file Paint2.java and file Face.java. You may get them from the ftp site or copy them onto a floppy disk in the Carpenter consulting room.

2. The goals of this assignment. This assignment has three goals:

  1. Give you practice with a classes and extensions of classes.
  2. Give you practice with writing and understanding small programs.

3. The program that you will modify. In this assignment, you will modify our version of the program that draws faces on the Drawing window. Obtain the files Paint2.java and Face.java from the ftp site or from a floppy disk in the Carpenter consulting room.

Start up a new project in CodeWarrior Java, using stationary CUCS Java GraphicsApplication. Replace method paint in file trivialApplication by method paint of file Paint2.java. Then add file Face.java to the project. (See assignment1 for instructions on doing all this.)

Execute this program; three faces will appear in the Drawing window.

4. What to do for this assignment. We ask you to modify the program in four ways, which are discussed below. After each change, make sure you "check out" the program before proceeding to the next step --execute the program and make sure it works as intended. It is much easier to check it out step by step than to test it only after you have made all the changes.

After you are finished, change method paint of trivialApplication so that an execution of the program will indicate that all four modifications were done properly. Hand in a snapshot that includes the Drawing window. Also, hand in copies of trivialApplication, class Face, and the three subclasses that you created. We realize that we won't be able to see colors on your black-and-white print out. That's okay; we will look at the program to see that changes are made correctly.

(0) Change class Face so that the color of the eyes on a face can be determined by the user of the class. Do this as follows.

(1) Add to the program a new class, SmilingFace, which is an extension of Face --put SmilingFace in a new file, called SmilingFace.java. An instance of SmilingFace should act just like an instance of Face, except that it has a smile for a mouth. Here are some hints for performing this step.

(2) Add two new classes, BroadSmile and NegativeSmile, each of which is an extension of SmilingFace. Follow the directions in (1) for adding a subclass. You decide on what the smile should look like in each case.

(3) Add a feature of your choice to the program; it should require changing Face and perhaps SmilingFace in some way. Below are examples, in increasing order of difficult, but you don't have to limit yourself to them. Use your imagination.

6. Grading guide. Each of the four items of Part A is worth three (2.5) points, so the whole assignment is worth 10 points.
Make sure you put suitable specifications on you methods and variables, otherwise points will be deducted.