Assignment 10: Interfaces

The goal of this assignment is to practice writing classes to implement an interface. There are two parts. You may be able to finish part 1 during the lab block.

As usual, make a new directory for this project and cd into it.

1. Revising the Set class

In the Set class you wrote for the previous assignment, you had choice--you could implement it using a character array or using a String. All of you chose to use a character array. To demonstrate that either would work, you will now re-implement set using a String instead. Do the following:

Hints: The String methods length(), charAt(int), and indexOf(String s). The last of these will tell you the location of the first occurrence of s in the receiver string, or -1 if it doesn't occur at all.

2. Shapes

Copy the files Shape.java and ShapeDriver.java from the class public directory to your directory for this assignment, and look at them in Xemacs.

In this part of the assignment, you will write classes for three types of shapes: Rectangles, right triangles, and isosceles triangles. They all should implement the Shape interface, that is, have methods for computing their area, computing their perimeter, and drawing a picture on the screen.

Write classes Rectangle, RightTriangle and IsoTriangle. Their draw methods should produce something like

**********
**********
**********

*
***
******
*********

     *
    ***
   *****
  *******
 *********
***********

Figuring out how to draw the triangles is the tricky part. You may discuss this with your classmates, but your code must be your own.

The constructors should query the user to get information about the dimensions for the shape.

As you go, update the driver so that it give the user the option to instantiate each shape class.

You also are responsible for documenting Shape.java.

3. Turn in

Create the script file as before (cat, rm, compile, and run)

 > a2ps -P sp (the name of the script file)

(This will print "two up", meaning two pages shown next to each other on one pice of paper. If you use a2ps on a Java file, it will format it nicely like in the handouts I've given in class. The command lpr works similarly except it does no formatting and doesn't print two up by default.)

Then turn in the hard copy by 5:00, Wed, Apr 6.


Thomas VanDrunen
Last modified: Sat Apr 2 10:32:58 CST 2005