Irregular polygon program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shihaoran
    New Member
    • Mar 2007
    • 4

    #1

    Irregular polygon program

    Thx for the help for my other two programs.

    Here is a hard one; it is about makeing irregular polygon; i could not figure it out, help pls....

    1. Implement a class IrregularPolygo n that contains an array list of Point2D.Double objects.

    2. The Point2D.Double class defines a point specified in double precision representing a location in (x, y) coordinate space. For example, Point2D.Double( 2.5, 3.1) constructs and initializes a point at coordinates (2.5, 3.1).

    3. Use the following declarations as a starting point for your lab work.

    import java.awt.geom.* ; // for Point2D.Double
    import java.util.Array List; // for ArrayList
    import gpdraw.*; // for DrawingTool

    public class IrregularPolygo n{
    private ArrayList <Point2D.Double > myPolygon;

    // constructors
    public IrregularPolygo n() { }

    // public methods
    public void add(Point2D.Dou ble aPoint) { }

    public void draw() { }

    public double perimeter() { }

    public double area() { }
    }
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by shihaoran
    Thx for the help for my other two programs.

    Here is a hard one; it is about makeing irregular polygon; i could not figure it out, help pls....

    1. Implement a class IrregularPolygo n that contains an array list of Point2D.Double objects.

    2. The Point2D.Double class defines a point specified in double precision representing a location in (x, y) coordinate space. For example, Point2D.Double( 2.5, 3.1) constructs and initializes a point at coordinates (2.5, 3.1).

    3. Use the following declarations as a starting point for your lab work.

    import java.awt.geom.* ; // for Point2D.Double
    import java.util.Array List; // for ArrayList
    import gpdraw.*; // for DrawingTool

    public class IrregularPolygo n{
    private ArrayList <Point2D.Double > myPolygon;

    // constructors
    public IrregularPolygo n() { }

    // public methods
    public void add(Point2D.Dou ble aPoint) { }

    public void draw() { }

    public double perimeter() { }

    public double area() { }
    }
    The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

    Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

    Then when you are ready post a new question in this thread.

    MODERATOR

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Changed thread title.

      Comment

      • ItachiOwnage
        New Member
        • May 2008
        • 1

        #4
        Hey, im new to the forums.....anyw ays, I'm doing the same problem stated above but I'm having a tough time starting the program because the drawingtool code slipped my mind. I can't seem to find it on java.sun.....
        can anyone show me how to declare the sketchpad and pencil? The main thing I can't remember is where i place it in the driver or a function?

        Thanks for the help.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          A Graphics object (the thing you draw on) even has a drawPolygon method so
          that part is easy. The perimeter of a polygon is simply the sum of the lengths
          of the line segments.

          The area can be calculated in a simple way if the polygon doesn't intersect itself,
          otherwise quite a bit of 101 geometry fiddling has to be performed.

          kind regards,

          Jos

          Comment

          Working...