Shapes

This is a somewhat detailed but interesting program that practices further the ideas of inheritance.

For this assignment, you will write a program that will read a text file containing descriptions of a bunch of shapes, and then open a Canvas window displaying those shapes.

For example, suppose your text file contains the following:

3
circle
255 0 0
100 200 60
rectangle
180 0 180
100 400 80 120
square
0 255 0
300 450 150

The very first line of the file indicates how many shapes will be coming. For each shape, the first line identifies the type of shape, the second line describes the RGB (red/green/blue) color of the shape, and the third line contains shape-specific information. If your program encountered this example, it would need to display a red circle with radius 60 and centered at (100,200), a purple rectangle with upper left corner (100,400), width 80, and height 120, and a green square with upper left corner (300,450) with edge width 150. In addition, each shape's area should be displayed in the center (more or less) of the shape.

There are many ways to write such a program, of course. For this assignment, you're going to use an existing APShape interface in APShape.java, and create three implementations of APShape: APCircle, APRectangle, and APSquare. (It turns out that there are already Shape and Rectangle classes in the standard Java library, so we'll just stick "AP" onto the class names to avoid conflict.) Your three classes will need to implement the methods getColor, setColor, load, and draw.

You will also need to create a ShapeTester class. This is the class that contains your main: it should read in the data from the file, and draw the shapes one at a time on a Canvas.

You may assume that the text file is correctly formatted.

Advice

In many ways, this is a very simple program. On the other hand, there are some tricky details. To manage the complexity of the task, you should start by making an incremental development plan. For example, the first version of your program might simply open the specified file and print its contents to standard output. The second version could include a loop that runs through the shapes in the file, printing only the shape-name line and terminating at the end of input. The third could parse the color integers into separate int variables, and then print those out. This kind of planned sequence of small steps, executed with discipline, can make a big job manageable. After each step, make sure to compile, test, and make backup copies of your code.

Have fun!