CS110 Introduction to Computing
Spring 2006

Assignment#4: Interfaces and Peer Objects
Due in class on Tuesday, February 21, 2006
Deadline extended to Tuesday, February 28, 2006

In this exercise, we will get hands-on experience with using Java interfaces, and the use of peer objects.

What to do: Read the entire Chapter 4 from Sanders & van Dam and make sure you understand the concepts of interfaces and peer objects. Your task is to follow the steps in Section 4.5 to implement the movable hat application.

Additionally: Do each o fthe following:

  1. The java programs do not contain any comments besides the header comment. Carefully, based on your understanding, add comments for each significant section of the code. For example: clearly identify constructor(s), required interface methods, individual tasks, etc.
  2. Add an additional constructor to the Hat class that takes the location and color as its parameters. Use this constructor in MoveableHatApp instead.
  3. Change the Hat to use rounded rectangles to change the appearance of the hat.
  4. The Draggable interface requires the implementation of 5 methods: setColor, setLocation, mousePressed, mouseDragged, and mouseReleased. Yet, the definitition of the class HatPart that implements Draggable does not include setColor and setLocation. Why?
  5. Does the Hat class need to implement the Draggable interface? Answer YES or NO. Then remove the words "implements Draggable" from the declaration of the Hat class (so it doesn' t implement it). Recompile and run the program. What happened? Did you answer correctly? Justify the final outcome.

Extra Credit: Modify the setSize method in Hat class to make use of the width and height parameters. That is, the size of the hat should be whatever the actual parameters of setSize are. Create a Hat that is 160 x 140. Think first before jumping ahead to do this. You will need to change some other things in the implementation as well!

Notes:

  1. Be sure that you have carefully read and understood the concepts covered in Chapters 4 of Sanders & van Dam and also the class notes.

Hand in: A prinout of the final version of the Java program from above. Include your answers from Questions above. Also, include a prinout of the picture produced by your program. Conclude your work by a short essay (just a few sentences) on your thoughts about your understanding of the Java programming concepts you have learned so far.

Also: As soon as you are successfully done, send an email to Deepak telling him that you were able to successfully complete your assignment.


Back to CS110 Spring 2006 Materials.