Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm not sure how to go about this. I attempted the constructors but I don't know if I did it right. Please help. :( ------------------------------

I'm not sure how to go about this. I attempted the constructors but I don't know if I did it right. Please help. :(

------------------------------

package A1; import java.awt.geom.Point2D; /** * The class SimplePolygon implements the Polygon interface. * * It is intended to be further extended by ConvexPolygon. * */ public class SimplePolygon implements Polygon { /********* protected fields ************************/ protected int n; // number of vertices of the polygon protected Point2D.Double[] vertices; // vertices[0..n-1] around the polygon boundary /********* protected constructors ******************/ /** * constructor used in the static factory method getNewPoly() * * @param size * number of edges (also vertices) of the polygon */ protected SimplePolygon(int size) { n = size; // TODO: place the rest of your code here } /** default no-parameter constructor */ protected SimplePolygon() { // TODO: place your code here } /********* public getters & toString ***************/ /** * static factory method constructs and returns an unverified simple-polygon, initialised * according to user provided input data. Runs in O(n) time. * * @return an unverified simple-polygon instance */ public static SimplePolygon getNewPoly() { int size = 0; // TODO: replace this line with your code SimplePolygon p = new SimplePolygon(size); // TODO: populate p.vertices[0..size-1] from input return p; } /** * * @return n, the number of edges (equivalently, vertices) of the polygon. */ public int getSize() { return n; } /** * * @param i * index of the vertex. * @return the i-th vertex of the polygon. * @throws IndexOutOfBoundsException * if {@code i = n }. */ public Point2D.Double getVertex(int i) throws IndexOutOfBoundsException { return vertices[i]; // TODO: replace this line with a try-catch code } /** * @return a String representation of the polygon in O(n) time. */ @Override public String toString() { return "xxx"; // TODO: replace this line with your code } /************** utilities *********************/ /** * * @param a * @param b * @param c * three input points. * @return twice the signed area of the oriented triangle (a,b,c). Runs in O(1) time. */ public static double delta(Point2D.Double a, Point2D.Double b, Point2D.Double c) { return 0; // TODO: replace this line with your code } /** * @param a * @param b * end points of line-segment (a,b). * @param c * @param d * end points of line-segment (c,d). * @return true if closed line-segments (a,b) and (c,d) are disjoint. Runs in O(1) time. */ public static boolean disjointSegments(Point2D.Double a, Point2D.Double b, Point2D.Double c, Point2D.Double d) { return true; // TODO: replace this line with your code } /** * @param i * @param j * indices of two edges of the polygon. * @return true if the i-th and j-th edges of the polygon are disjoint. Runs in O(1) time. * @throws IndexOutOfBoundsException * if i or j are outside the index range [0..n-1]. */ public boolean disjointEdges(int i, int j) throws IndexOutOfBoundsException { return true; // TODO: replace this line with a try-catch code } /** * This method verifies whether the claimed "simple-polygon" is indeed simple. * * @return true if the polygon is simple. Runs in O(n^2) time. */ public boolean isSimple() { return true; // TODO: replace this line with your code } /************ perimeter & area ***************/ /** * * @return the sum of the edge lengths of the polygon. Runs in O(n) time. */ public double perimeter() { return 0; // TODO: replace this line with your code } /** * * @return area of the polygon interior. Runs in O(n) time not counting the simplicity test. * @throws NonSimplePolygonException * if the polygon is non-simple. */ public double area() throws NonSimplePolygonException { return 0; // TODO: replace this line with a try-catch code } }

-------------------------------------------------------------------------------------------------------------------------

image text in transcribed

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions