CS 10, Fall 2008
Assignment 4

In parts 1 and 2, you will implement a superclass (FigurePrinter) and two subclasses of it (RectanglePrinter and TrianglePrinter). See the javadocs from our solution to learn the interfaces you must implement.

In part 3, you will write an application (FigureDisplayer) that displays such figures.

Due: Wednesday, November 19, 9:00 pm
Worth: 100 homework points

  1. Complete FigurePrinter.java to provide the public interface described in the javadocs. Be sure to read the method descriptions in those javadocs too, as they are more detailed than the following notes.
  2. Write the two subclasses, RectanglePrinter and TrianglePrinter, to have the same public interface shown in our solution's javadocs (your solution should have javadoc comments too, but they are not required). Both subclasses store data in addition to the data stored in FigurePrinter, and both classes must override print() and equals(Object other). FigureTester.java should be used to test these classes too - but first remove the six lines labelled "/*TEMP" or "TEMP*/" and run it with either r (for rectangle) or t (for triangle) as the first command line argument. See the test runs below.
    1. Write RectanglePrinter.java.
      • See part 2a of the implementation notes.
      • If you run FigureTester as follows (after deleting the TEMP comment delimiters):
        java FigureTester r
        results should match this rectangle test run.
    2. Write TrianglePrinter.java
      • See part 2b of the implementation notes.
      • If you run FigureTester as follows (after deleting the TEMP comments):
        java FigureTester t
        results should match this triangle test run.
  3. Write an application called FigureDisplayer.java to display a user-specified number of random rectangle and triangle figures.
  4. Be sure your classes will compile and execute correctly at CSIL. Additional copies of FigureTester.java, the FigurePrinter.java skeleton and other files are in ~mikec/cs10/hw4/. There are four files to turn in:
    turnin hw4@cs10 FigurePrinter.java RectanglePrinter.java TrianglePrinter.java FigureDisplayer.java
    Alternatively, you can use the following procedure if you want:
    • Create a new directory (if necessary), and copy each of the required files to it.
    • Change to that directory. Verify that it contains no other .java files. Then type:
      turnin hw4@cs10 *.java
    Late projects may not be accepted.

Updated 11/5/08 by C. Michael Costanzo