Home
Site Map
Useful Tools
Graphing Calc

Scientific Calculator

Super Classes Are Great II

Note: We are going to append a '2' to each class name in this section to differentiate this version of the classes.

Your task

Refactor the Rectangle and Triangle classes. This time move the common methods up to the superclass Polygon2. Of particular importance, is the way that InteractiveMath has been refactored. Look carefully at the one and only arraylist that we have

Class: Polygon2 (superclass of Triangle2, Rectangle2)


instance Variables
  • private int color;
  • private int numSides
  • private double width;
  • private double height
Accesor Methods
  • public double getArea(); //returns the area of the rectangle
  • public int getColor()
  • public double getWidth()
  • public double getHeight();

Class: Rectangle2 extends Polygon2


instance Variables
None needed (see superclass)
Accesor Methods //override each of the superclass
  • public double getArea(); //returns the area of the triangle

Class: Triangle2 extends Polygon2



instance Variables
None needed
Accesor Methods //override each of the superclass
  • public double getArea(); //returns the area of the rectangle
  • public double getAltitudeLength() //returns the length of the altitude

Class: InteractiveMath2

I already implemented computeNetArea() which you should use as a model to complete computerNetPerimeter()

instance Variables
  • ArrayList<Polygon2> polys;
Accesor Methods
  • public double computeNetArea(){ //@ returns the area of the rectangles and triangles
  • public void printDetails()//loop over all objects, print each object's variables on a separate line . Make sure that you print out the altitude length of each Triangle

What problem would we have if we wanted to add a Circle Class?

Answer: Big problems

How to solve the Circle Dilemna
Sitemap