Abstract Classes: Shapes
-
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.
-
Make a project called L9 then download and import Shapes-starter.jar
Your directory should look like this:
W5L2/ └── src ├── Circle.java ├── Point.java ├── Shape.java ├── Rectangle.java ├── TestProgram.java └── Triangle.java
-
Note that the Shape class is abstract and cannot be instantiated.
-
Use the javadoc to implement the
Circle
,Rectangle
, andTriangle
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
, andtoString
methods are provided for you. -
Uncomment the
toString
method at the end of implementing each class.
-
-
Implement the
compareTo
method in theabstract
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.
|