Write a java program using methods to compute and output the area of an n sided
ID: 3697515 • Letter: W
Question
Write a java program using methods to compute and output the area of an n sided polygon where the are is defined by the following mathemetical formula:
area = (n* (s * s) ) / (4 x tan(3.1416/n))
where s = length of a side of a regular polygon with all sides of equal length and all angles are the same and n = the number of sides. for this assignment set n = 5 for a pentagon and let the side s vary from 1 to 20.
your output should let the size of a side vary from 1 to 20. you should have one method to compute the resulting area and another method to determine whether the area is considered small, medium, or large according to following table :
Area Classification
<= 10 small
11 to 25 medium
> 25 Large
your column headings should include side, area and classification.
Explanation / Answer
import java.util.Scanner;
public class AreaOfAregularPolygon
{
public static void main (String[] args)
{
Scanner input = new Scanner (System.in);
System.out.println(" Enter the number of sides in polygon");
int n = input.nextInt();
System.out.println(" Enter the distance between two points");
double s = input.nextDouble();
if((s>>1&&s<<20)&&n==5)
{
double area = (n *(s*s)) / (4 * Math.tan(Math.PI / n));
System.out.println (" Area of regular pentagon is " + area);
If(area<=10)
{
System.out.println(" area is small");
}
Else if(area>=11&&area<=25)
{
System.out.println(" area is medium");
}
Else
{
System.out.println(" area is large");
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.