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 ( |
compareTo results might vary, but the signs of these results should match).
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.
TEMP comment delimiters):java FigureTester rTEMP comments):java FigureTester tjava.util.Random.]
ArrayList<FigurePrinter> to store random figures (either 5 or
the number requested on the command line). For each figure, randomly select: (1) rectangle or
triangle - our solution uses the nextBoolean
method of Random to select a boolean value (true means rectangle); (2) a random character
in the printable range of the ASCII codes (33 to 126, by proper use of the nextInt
method of Random) - you can run this
ListOfPrintable.java to see the complete list of these
characters and codes; (3) a random offset in the range 0 to 50; (4) a random width less than or
equal to 20; and if a rectangle, then (5) a random height less than or equal to 10.
compareTo method of FigurePrinter correctly, you
can use the Collections.sort method to do so in a single statement. [See
java.util.Collections.]
java FigureDisplayer 30java FigureDisplayer 3 765 and
java FigureDisplayer 3 792~mikec/cs10/hw4/.
There are four files to turn in:
.java files.
Then type:
turnin hw4@cs10 *.java