public class Polygon {

    // Declare and initialize default values.
    private int numSides = 4;
    private double sideLength = 10.0;
    private double xCoord = 0.0;
    private double yCoord = 0.0;
    private String shapes = "shapes";
    public double perimeter = 0;

    // Create constructor with default values.
    public Polygon() {

    // Create constructor with new numSides and sideLength values.
    public Polygon(int numSides, double sideLength) {
        this.numSides = numSides;
        this.sideLength = sideLength;
        this.xCoord = 0;
        this.yCoord = 0;

    // Create constructor with new numSides, sideLength, xCoord, and yCoord
    // values.
    public Polygon(int numSides, double sideLength, double xCoord, double yCoord) {
        this.numSides = numSides;
        this.sideLength = sideLength;
        this.xCoord = xCoord;
        this.yCoord = yCoord;

    // get numSides method
    public int getnumSides() {
        return this.numSides;
    }// end get numSides

    // set numSides method.
    public void setnumSide(int numSides) {
        this.numSides = numSides;
    }// end set numSides

    // get sideLength method.
    public double getsideLength() {
        return this.sideLength;
    }// end get sideLength

    // set sideLength method.
    public void setsideLength(double sideLegth) {
        this.sideLength = sideLength;
    }// end set sideLength

    // get x-coordinate method.
    public double getxCoord() {
        return this.xCoord;
    }// end get sidexCoord

    // set x-coordinate method.
    public void setxCoord(double xCoord) {
        this.xCoord = xCoord;
    }// end set xCoord

    // get y-coordinate method.
    public double getyCoord() {
        return this.yCoord;
    }// end get yCoord

    // set y-coordinate method.
    public void setyCoord(double yCoord) {
        this.yCoord = yCoord;
    }// end set yCoord

    // Calculate Perimeter.
    public double getperimeter() {
        return this.numSides * this.sideLength;

    // toString method
    public String toString() {
        String shapes;
        shapes = "toString () results: " + numSides + ", " + sideLength + ", "
                + xCoord + ", " + yCoord + "\ngetNumSides() results:"
                + numSides + "\ngetsidelength() results: " + sideLength
                + "\ngetxCoord() results:" + xCoord + "\ngetyCoord results:"
                + yCoord + "\ngetperimeter() results: " + perimeter
                + "\nsetNumSides() results:" + "\nsetsidelength results:"
                + "\nsetxCoord() results: " + "\nsetyCoord results:" + " \n ";
        return shapes;


public class TestPolygon {
    public static void main(String [] args){
         //Create 5 polygon objects
         Polygon shapes1 = new Polygon();
         Polygon shapes2 = new Polygon(3,2.0,1.0,1.0);
         Polygon shapes3 = new Polygon(5,3.0,5.0,1.0);
         Polygon shapes4 = new Polygon(6,4.0,2.0,6.0);
         Polygon shapes5 = new Polygon(4,2.0,3.0,7.0);

What am I doing wrong? First off I cant get my perimeter to print correctly. This is what I was asked to create. I know I am close.

A private double data field named yCoord that defines the y-coordinate of the center of
the polygon. The default value should be 0.0.
· A no argument constructor that creates a Polygon using the default number of sides,
default side length and default x- and y-coordinates.
· A constructor that creates a Polygon using a specified number of sides, side length and
x- and y-coordinates.
· Getter and setter methods for all data fields
· A getPerimeter() method that returns a double value representing the sum of all sides.
· A toString() method that displays the number of sides, side length, x-coordinate and y- coordinate values in String format.
Be sure your code compiles. (In the next question, you will create a TestPolygon class and test each
of the methods)
Write a Java test program, named TestPolygon, to create five different polygons. When creating the
five polygons, create one using the no argument constructor. For the remaining four, feel free to use
any number of sides, side length and x-, and y-coordinates that are not equal to the default values
and not equal to each other. For each of the five polygons, call all of the methods and display the
results. For example for a Polygon with 3 sides, side length of 2.0 and x-coordinate and y- coordinates of 1.0, the following output may be appropriate.
toString() results: (3, 2.0, 1.0,1.0)
getNumSides() results: 3
getSideLength() results: 2.0
getXCoord() results: 0.0
getYCoord() results: 0.0
getPerimeter() results: 6.0
setNumSides(4) results: 4
setSideLength(3) results: 3.0
setXCoord(2.0) results: 2.0
setYCoord(2.0) results: 2.0

Keep in mind, for five Polygons, you will have five different output results. Also, note there is no requirement to actually draw a Polygon.