Question about my class
This class keeps causing my computer to freeze up when I test it,
is there a problem with my Arrays? Is it the GetArea method? What would be a better way to implement the getArea method for the area of a convex polygon?
import java.awt.Color;
import java.awt.Point;
/**
* The ConvexPolygon class of the workspace program.
*
* @author Rossiter Fahan
* @version Program 2
*/
publicclass ConvexPolygonimplements Shape
{
// instance variables
private java.awt.Point[] vertices;
private java.awt.Color color;
privateboolean filled;
/**
* Constructor for objects of class ConvexPolygon
*/
public ConvexPolygon(java.awt.Point[] vertices, java.awt.Color color,boolean filled)
{
this.vertices = vertices;
this.color = color;
this.filled = filled;
}
/**
* Returns a specified vertex.
*
* @param indexThe index number of the specified point.
* @returnPoint of the specified vertex
*/
public java.awt.Point getVertex(int index)
{
return vertices[index];
}
/**
* Sets the specified vertex of the polygon.
*
* @param indexThe index number of the specified vertex.
* @param pointThe new point
*/
publicvoid setVertex(int index, java.awt.Point point)
{
vertices[index] = point;
}
/**
* Tests if two Polygons are logically equivalent
*
* @paramthe 2nd Polygon
* @returntrue or false
*/
publicboolean equals(ConvexPolygon poly)
{
int i=0;
boolean equalPoints =true;
if(polyinstanceof ConvexPolygon)
{
for(i++; poly.vertices.length > i; i=0)
if(!(getVertex(i).equals(poly.getVertex(i))))
equalPoints =false;
if(equalPoints && getFilled() == poly.getFilled() && getColor() == poly.getColor())
returntrue;
else
returnfalse;
}
else
returnfalse;
}
publicdouble getArea()
{
int i = 0;
double temp1 = vertices[vertices.length-1].x * vertices[i].y;
double temp2 = vertices[vertices.length-1].y * vertices[i].x;
for(i++; vertices.length > i; i=0)
temp1 += vertices[i].x * vertices[i+1].y;
for(i++; vertices.length > i; i=0)
temp2 += vertices[i].y * vertices[i+1].x;
return (0.5 * (temp1 - temp2));
}
public java.awt.Color getColor()
{
return color;
}
publicvoid setColor(java.awt.Color color)
{
this.color = color;
}
publicboolean getFilled()
{
return filled;
}
publicvoid setFilled(boolean filled)
{
this.filled = filled;
}
publicvoid move(java.awt.Point point)
{
int i=0;
for(i++; vertices.length > i; i=0)
vertices[i].translate(point.x, point.y);
}
}

