Must be solved without using math
public class Polygon {
public Point[] points;
/**
*
/**
*
* @param _points
*
* Populate the instance variable array points
with items of _points.
*
* See the test data to determine null case
scenario, etc.
*
* Make sure all objects (including arrays)
copying is done using instance copy, not reference copy.
*/
public Polygon(Point[] _points) {
}
//DO NOT MODIFY!
public String toString() {
String result =
"("+points[0].x+", "+points[0].y+") -> ";
for(int i=1; i <
points.length; i++) {
result+="("+points.x+", "+points.y+") -> ";
}
if(points.length >
1)
result+="("+points[0].x+", "+points[0].y+")";
else
result =
result.substring(0, result.length()-4);
return result;
}
/**
*
* @return index of the first point that has the
same values for x and y coordinates
* return -1 if no such point exists.
*/
public int firstPointWithSameXY() {
return 0;
}
/**
*
* @return index of the last point that lies on
the origin (0, 0)
* return -1 if no such point exists.
*/
public int lastPointAtOrigin() {
return 0;
}
/**
*
* @return true if every point is further from
origin than the last point,
* false otherwise.
*/
public boolean goingFurtherFromOrigin()
{
return false;
}
/**
*
* @return the sum of all sides of the
polygon
* first point to second,
* second point to third,
* second last point to last,
* last point back to first
*/
public double circumference() {
return 0;
}
/**
*
* @return index of the first point that is on
origin (0, 0).
* return -1 if no such point exists.
*/
public int firstPointOnOrigin() {
return 0;
}
/**
*
* @return index of the last point that has the
same values for x and y coordinates
* return -1 if no such point exists.
*/
public int lastPointWithSameXY() {
return 0;
}
/**
*
* An edge is the line between two adjacent
vertices/points in a polygon.
* @return the length of the longest edge.
* For example if there are three consecutive
points (2,3) -> (7,3) -> (8,3),
* then (2,3) -> (7,3) is one side, and (7,3)
-> (8,3) is a second side.
*/
public double longestEdge() {
return 0;
}
/**
*
* @param minLength
* @param maxLength assume maxLength >=
minLength
* @return number of edges in the polygon that
have a length between the two lengths
* (inclusive on both sides)
*/
public int countEdgesBetween(int minLength, int
maxLength) {
return 0;
}
* @param x
* @param y
*
* Populate the instance variable array, points, using the arrays
x and y.
* Each corresponding pair in the two arrays; x, y;
represents one point.
*
* use the first n items where n is the smaller of x.length and
y.length
*
* in case of either array being null, initialize the array to an
empty one.
*/
public Polygon(int[] x,
int[] y) {
}
Must be solved without using math public class Polygon { public Point[] points; /** * /**
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Must be solved without using math public class Polygon { public Point[] points; /** * /**
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!