Chris Pollett>Old Classes>CS102, Spring 1999>Hw1

CS 102
HW#1

        Due on the web by 4pm, Tuesday, Feb. 2, 1999. This homework will be graded out of 10. Two points of this will be on how well your code is documented. Roughly you should follow the documentation conventions of the cRecorder.java file below. In addition any algorithms which are obscure should be clarified with comments. Also state pre-conditions and post-conditions for each method you write. Now for the homework. Read to page 48 in Bailey and Chapter 9,10 in D&D; Then make a subdirectory of your homepage directory called hw1 (make sure you have the case right). Put your source code for this homework here.

  1. Write an applet named Face.java that when compiled and run draws a face. Be creative. However, you need to use at least one polygon, one oval, one arc, one line, and one rectangle. You also need to use at least three colors and have a title printed at the top in something other than the default font. See below for an example face.
    An image of a face.
  2. Download the file cRecorder.java This class provides some methods to record a list of objects. Write a method toString for this cRecorder class (thus overriding the toString method inherited from Object) that returns a string which lists on separate lines the items stored in an instance of cRecorder. You should use StringsBuffer's to do this. Then write an applet ButtonRecorder.java which uses a BorderLayout to draw a label, three buttons, and a textarea. See the applet below to see how it should look. The applet should record left/right button presses (using the string "left" for a left press and "right" for a right press) into a cRecorder instance. When the middle button is pressed it should output a history of the left/right buttons pressed to the textarea. It should then clear the contents of the cRecorder instance. Please experiment with the applet below to see what I mean.
    An applet with three buttons on the top and a textarea on bottom.