SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 3 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 20 Nov 2017 My Price 10.00

second program in the java realm of programming.

This is my second program in the java realm of programming. I was able to write up the "polygon" file and it is able to compile. "TestPolygon" I found on this site and tried to modify it to be able to run. Something is not executing properly. The "TestPolygon" file should be separate from the "Polygon" file? Or should one be copied into another for it to run properly? Please advise and touch on the "TestPolygon" program. Thank you!

  • /*
    *
    *
    *
    */

    public class Polygon {

        private int numSides;      //number of sides
        private double sideLength; //length of each side
        private double xCoord;     //x-coordinate of th center of the polygon
        private double yCoord;     //the y-coordinate
        private double apothem;    //defines the apothem
        private double perimeter;

        // no argument constructor
        
        public Polygon() {
            this.numSides = 4;
            this.sideLength = 2.0;
            this.xCoord = 0.0;
            this.yCoord = 0.0;
            this.apothem = 4.0;
            this.perimeter = 16.0;
        }

            public Polygon(int _numSides, double _sideLength, double _xCoord, double _yCoord, double _apothem) {

            this.numSides = _numSides;
            this.sideLength = _sideLength;
            this.xCoord = _xCoord;
            this.yCoord = _yCoord;
            this.apothem = _apothem;

        }

        // area is doubled

            public double getArea() {
            perimeter = numSides * sideLength;
            double area = (0.5) * apothem * perimeter;
            return area;

        }

        //getter & setters

        public int getNumSides() {
            return numSides;
        }

        public void setNumSides(int numSides) {
            this.numSides = numSides;
        }

        public double getSideLength() {
            return sideLength;
        }

        public void setSideLength(double sideLength) {
            this.sideLength = sideLength;
        }

        public double getxCoord() {
            return xCoord;
        }

        public void setxCoord(double xCoord) {
            this.xCoord = xCoord;
        }

        public double getyCoord() {
            return yCoord;
        }

        public void setyCoord(double yCoord) {
            this.yCoord = yCoord;
        }

        public double getApothem() {
            return apothem;
        }

        public void setApothem(double apothem) {
            this.apothem = apothem;
        }

        public double getPerimeter() {
            return perimeter;
        }

        public void setPerimeter(double perimeter) {
            this.perimeter = perimeter;
        }

        public String toString() {
            return "Polygon definitions[" + "number of sides=" + numSides + ", Each side length=" + sideLength + ", xCoord=" + xCoord + ", yCoord=" + yCoord + ", apothem=" + apothem + ']';
        }
    }
    /*
     *
     *
     *
     */

    public class TestPolygon {

        public static void main(String[] args) {

            //create Polygon class object with no parameters

            Polygon poly1 = new Polygon();

            //call all methods

            System.out.println(poly1.toString());
            System.out.println("\tNumber of sides: " + poly1.getNumSides() + "\n"
                    + "\tPolygon side length: " + poly1.getSideLength() + "\n"
                    + "\tThe X coordinate: " + poly1.getxCoord() + "\n"
                    + "\tThe Y coordinate: " + poly1.getxCoord() + "\n"
                    + "\tPolygon's apothem: " + poly1.getyCoord() + "\n"
                    + "\tThe polygon perimeter: " + poly1.getPerimeter() + "\n"
                    + "\tThe polygon area: " + poly1.getArea());


            //create 5 Polygon class object with parameters

            Polygon poly[] = new Polygon[5];

            //initialize the objects with values

        //[Sides,sideLength,xCoord,yCoord,apothem]


            poly[0] = new Polygon(3, 2.0, 1.0, 1.0, 1.0);       
        poly[1] = new Polygon(8, 7.1, 1.0, 1.0, 5.0);
            poly[2] = new Polygon(6, 4.1, 0.0, 0.0, 2.0);
            poly[3] = new Polygon(7, 4.0, 2.0, 2.0, 4.0);
        poly[4] = new Polygon(8, 3.0, 1.0, 5.0, 6.0);

            //display the values

            for (int i = 0; i < poly.length; i++) {
                System.out.println("----------------------------------------");
                System.out.println(poly[i].toString());
                System.out.println("\tNumber of sides: " + poly[i].getNumSides());
                System.out.println("\tPolygon side length: " + poly[i].getSideLength());
                System.out.println("\tThe X coordinate: " + poly[i].getxCoord());
                System.out.println("\tThe Y coordinate: " + poly[i].getyCoord());
                System.out.println("\tPolygon's apothem: " + poly[i].getApothem());
                System.out.println("\tThe polygon perimeter: " + poly[i].getPerimeter());
                System.out.println("\tThe polygon area: " + poly[i].getArea());
            }
        }
    }

Answers

(5)
Status NEW Posted 20 Nov 2017 02:11 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)