class Point { private float x; private float y; public Point(float x, float y) { changeCoords(x, y); } public void changeCoords(float x, float y) { this.x = x; this.y = y; } @Override public String toString() { return "(" + x + ", " + y + ")"; } } class Polygon { private final Point[] points; public Polygon(int n) { points = new Point[n]; for (int i = 0; i < n; i++) { points[i] = new Point(0, 0); } } public Polygon(float[] coords) { if (coords.length % 2 != 0) { throw new IllegalArgumentException("len is odd"); } int n = coords.length / 2; this(n); for (int i = 0; i < n; i++) { points[i] = new Point(coords[2 * i], coords[2 * i + 1]); } } @Override public String toString() { StringBuilder sb = new StringBuilder("Polygon: "); for (Point p : points) { sb.append(p.toString()).append(" "); } return sb.toString(); } } public class Main { public static void main(String[] args) { Polygon poly1 = new Polygon(3); System.out.println(poly1); float[] coords = {0, 0, 1, 0, 1, 1, 0, 1}; Polygon poly2 = new Polygon(coords); System.out.println(poly2); } }