Untitled
unknown
java
3 years ago
2.2 kB
4
Indexable
package Labs.Assignment9;
import java.util.*;
public class QuestionNine
{
public static void main(String[] args)
{
RegularPolygon rp1 = new RegularPolygon();
RegularPolygon rp2 = new RegularPolygon(6, 4);
RegularPolygon rp3 = new RegularPolygon(10, 4, 5.6, 7.8);
System.out.printf("Regular Polygon 1 Perimeter : %f\n",rp1.getPerimeter());
System.out.printf("Regular Polygon 1 Area : %f\n",rp1.getArea());
System.out.printf("Regular Polygon 2 Perimeter : %f\n",rp2.getPerimeter());
System.out.printf("Regular Polygon 2 Area : %f\n",rp2.getArea());
System.out.printf("Regular Polygon 2 Perimeter : %f\n",rp3.getPerimeter());
System.out.printf("Regular Polygon 2 Area : %f\n",rp3.getArea());
}
}
class RegularPolygon
{
private int n = 3;
private double side = 1.0;
private double x = 0;
private double y = 0;
RegularPolygon(){}
RegularPolygon(int n, double side)
{
this.n = n;
this.side = side;
double x = 0;
double y = 0;
}
RegularPolygon(int n, double side, double x, double y)
{
this.n = n;
this.side = side;
this.x = x;
this.y = y;
}
public int getN()
{
return n;
}
public void setN(int n)
{
this.n = n;
}
public double getSide()
{
return side;
}
public void setSide(double side)
{
this.side = side;
}
public double getX()
{
return x;
}
public void setX(double x)
{
this.x = x;
}
public double getY()
{
return y;
}
public void setY(double y)
{
this.y = y;
}
public double getPerimeter()
{
return n * side;
}
public double getArea()
{
return (n * side * side) / (4 * Math.tan(Math.PI / n));
}
}
Editor is loading...