Abstract Classes: Shapes

Objectives
  • Practice OO programming and inheritance.

  • Introduce abstract classes.

  • Implement (override) some abstract methods from an abstract class.

  • Practice using of the Comparable interface for sorting.

Getting Started

Your directory should look like this:

L9/
└── src
    ├── Circle.java
    ├── Point.java
    ├── Shape.java
    ├── Rectangle.java
    ├── TestProgram.java
    └── Triangle.java
Instructions
  • Note that the Shape class is abstract and cannot be instantiated.

  • Use the javadoc to implement the Circle, Rectangle, and Triangle classes, one at a time.

    • If you’re unsure what mathematical formulas to use in the classes, google it.

    • Test each class incrementally.

    • The instance variables, equals, hashCode, and toString methods are provided for you.

    • Uncomment the toString method at the end of implementing each class.

  • Implement the compareTo method in the abstract Shape class.

  • Finish testing and then answer the questions in the main method of the TestProgram.


Important
Once you have completed the code, tested each class using TestProgram.java and answered the additional questions, show your code to the TA or helper.