SE-1021 Software Development 2
Lab 2: Inheritance (using shapes)

Outcomes

Assignment

I have created a shape drawing application that creates the following illustration:

Your assignment is to write the Java classes Shape, Triangle, LabeledTriangle, Rectangle, LabeledRectangle, and Circle, which form the inheritance hierarchy illustrated in the UML class diagram below. Look carefully at the specifiers for the class attributes, and note the distinction between private, public, and protected attributes.

Put each of these classes in a package named se1021.lab2.<yourname>

The ShapeCreatorApp class is already completed and you can use it without making any modifications to the source code other than changing the import statement to include your shape classes (note especially that you must keep it in the se1021.lab2 package).

WinPlotter is a class that I wrote, but you need to download it and include it into your project. You can find the Javadoc for WinPlotter's methods here.

Inheritance allows us to define certain key attributes of every shape (for example, every shape has a cartesian origin specified by the attributes xo and yo. Due to inheritance, every class that extends Shape inherits these attributes (i.e. they do not and should not be redefined in any of the subclasses). Additionally, due to the fact that these are protected attributes, these attributes are also visible in every class that extends Shape.

Note that the classes that extend Shape define their own specific attributes; for example Rectangle defines attributes that represent a rectangles width and height, Triangle defines attributes that represent a triangles base and height, and Circle defines an attribute that represents a circle's radius. Continuing in this fashion, both LabeledRectangle and LabeledTriangle define attributes that represent labels that are used to identify those objects.

Every class in this inheritance hierarchy implements a draw() method. Shape implements a very basic draw functionality that simply draws a dot (using WinPlotter's drawPoint() method) at the shape's origin. The other derived shapes all provide their own custom, overridden, versions of this method that implement the specific drawing behavior of each specific type of shape (if these methods weren't overridden, everything would just be drawn as a dot).

Note that the draw() methods all take a single argument, which is a reference to the WinPlotter object created at the beginning of the ShapeCreatorApp class. Thus all shapes use the same WinPlotter object for drawing.

To help you understand what you must write for each class (and how to draw each shape), read the Javadoc for the Shape-derived classes found here.

Lab Submission (due date in Blackboard)

Upload your .java files through Blackboard (assignment "Lab 2: Inheritance"). Upload each file separately; you should upload a total of six files. You do not have to upload ShapeCreatorApp.java, since you are not modifying that class. Be sure to keep copies of all your java files, in case something gets lost.

Your grade will be based on the following criteria: