Home
Site Map
Useful Tools
Graphing Calc

Scientific Calculator

## Why Abstracts Classes Are Useful

Implement all methods of the Rectangle, Circle and Triangle classes described below. Then download InteractiveMath and implement its methods

### Class: Shape (superclass for all shape types)

instance Variables
• private int color;
Accesor Methods
• public double getArea(); What goes here?
• public int getColor()

### Class: abstract Polygon3 extends Shape

(superclass of Triangle3, Polygon3)
Constructor
• public Polygon3(int sides) //this should use the paramater to initalize the instance varaible `numSides`
Instance Variables
• private int numSides
Accesor Methods
• no methods

### Class: Triangle3 extends Polygon3

Constructor
• Public Triangle3( ) //this should initalize the instance variables of Polygon as shown below;
```  public Triangle3(double b,double height)
{
super(3);
base =b;
height h
}
```
instance Variables
• double base
• double height
Accesor Methods //override each of the superclass
• public double getArea(); //returns the area of the triangle

### Class: Circle extends Shape

Constructor
• Public Circle(double r) //this should initalize the radius to the value of `r`;
instance Variables
Accesor Methods
• public double getArea(); //returns the area of the circle

## Insightful Few Lines of Code

`Shape s = new Triangle3();`
Class: InteractiveMath3
I already implemented `computeNetArea()`

instance Variables
• ArrayList<Shape> shapes;
Accesor Methods
• public double computeNetArea(){ //@ returns the area of the rectangles, circles and triangles
• public void printColors()//loop over all objects, print each object's variables on a separate line .
Sitemap