I was assigned a project in which I was to create a series of classes to represent shapes, then create a Canvas class to represent the canvas. For the most part, this was pretty simple but I ran across a few problems. The first of these problems is in my Triangle class. In order to find the area of the triangle, I used the .Math library and functions, sqrt() and hypot() however upon compiling, I am told that these functions cannot be found, and yes, I did import the .Math library. Below is the code for the getArea() function I am getting the errors in.

My next problem is really just my incompetency in math I don't really get how to find the area of a Convex Polygon. My teacher told us to head to this site for reference but I'm still lost (may be a result of not sleeping for 30 hours straight hehe ) http://www.mathwords.com/a/area_convex_polygon.htm. But any help in that area would be awesome.Code:public double getArea() { double len1, len2, len3, semip, area; len1 = hypot( (double)(p1.x - p2.x), (double)(p1.y - p2.y) ); len2 = hypot( (double)(p2.x - p3.x), (double)(p2.y - p3.y) ); len3 = hypot( (double)(p1.x - p3.x), (double)(p1.y - p3.y) ); semip = (len1 + len2 + len3) / 2; area = sqrt( semip*(( semip - len1 )*( semip - len2 )*( semip - len3 )) ); return area; }

My last bit of trouble is with this Canvas class. In the last few functions of the class, we are told to make functions to return an ArrayList of a specific shape. I'm a little confused on how to check for the shape. Below is the code for that class.

Thanks in advance for your help!Code:import java.awt.Color; import java.util.ArrayList; public class Canvas { //variables private ArrayList<Shape> shapes; public Canvas() { shapes = new ArrayList<Shape>(); } public void add( Shape shape ) { shapes.add( shape ); } public Shape remove( int index ) { Shape removed = shapes.get( index ); shapes.remove( index ); return removed; } public Shape get( int index ) { return shapes.get( index ); } public int size() { return shapes.size(); } public ArrayList<Circle> getCircles() { ArrayList<Circle> circles = new ArrayList<Circle>(); for( int ctr = 0; ctr < shapes.size(); ctr++ ) { if( shapes.get( ctr ) instanceof Circle ) { circles.add( shapes.get( ctr ) ); } } return circles; } public ArrayList<Rectangle> getRectangles() { ArrayList<Rectangle> rectangles = new ArrayList<Rectangle>(); for( int ctr = 0; ctr < shapes.size(); ctr++ ) { if( shapes.get( ctr ) instanceof Rectangle ) { rectangles.add( shapes.get( ctr ) ); } } return rectangles; } public ArrayList<Triangle> getTriangles() { ArrayList<Triangle> triangles = new ArrayList<Triangle>(); for( int ctr = 0; ctr < shapes.size(); ctr++ ) { if( shapes.get( ctr ) instanceof Triangle ) { triangles.add( shapes.get( ctr ) ); } } return triangles; } public ArrayList<ConvexPolygon> getConvexPolygons() { ArrayList<ConvexPolygon> convexPolygons = new ArrayList<ConvexPolygon>(); for( int ctr = 0; ctr < shapes.size(); ctr++ ) { if( shapes.get( ctr ) instanceof ConvexPolygon ) { convexPolygons.add( shapes.get( ctr ) ); } } return convexPolygons; } public ArrayList<Shape> getShapesByColor( Color color ) { ArrayList<Shape> colors = new ArrayList<Shape>(); for( int ctr = 0; ctr < shapes.size(); ctr++ ) { if( shapes.get( ctr ).getColor instanceof Color ) { colors.add( shapes.get( ctr ) ); } } return colors; } public double getAreaOfAllShapes() { double area; for( int ctr = 0; ctr < shapes.size(); ctr++ ) { area += shapes.get( ctr ).getArea(); } return area; } }