128k views
3 votes
Write a program that will prompt a user to input coordinates for all the corners for drawing a quadrilateral. The program should draw the quadrilateral on AutoCAD screen and print out all the coordinates with x and y coordinates only. Use GETPOINT, CAR, and CADR for writing the following program. Make sure this program will work with any coordinates that a user may input. None of the numerical coordinates should be in the programming code; in another words, do not HARD CODE the coordinates.

1 Answer

4 votes

Answer:

See explaination

Step-by-step explanation:

public class Drawquadrilatral

{

public void paintComponent(Graphics g)

{

super.paintComponent(g);

Polygon p = new Polygon();

for (int k = 0; k < 7; k++)

p.addPoint((int) (200 + 60 * Math.cos(k * 2 * Math.PI / 9)),

(int) (200 + 60 * Math.sin(k * 8 * Math.PI / 5)));

g.drawPolygon(p);

Polygon s = new Polygon();

for (int k = 0; k < 360; k++)

{

double m = k / 360.0;

s.addPoint((int) (150 + 50 * m * Math.cos(8 * m * Math.PI)),

(int) (150 + 50 * m * Math.sin(8 * m * Math.PI)));

}

g.drawPolygon(s);

}

public static void main(String[] args)

{

JFrame frame = new JFrame();

frame.setTitle("DrawPoly");

frame.setSize(350, 250);

frame.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

});

Container contentPane = frame.getContentPane();

contentPane.add(new DrawPolyPanel());

frame.show();

}

}

User Ajay Chaudhary
by
5.6k points