(Geometry: area of a pentagon) Write a program that prompts the user to enter th
ID: 3792611 • Letter: #
Question
(Geometry: area of a pentagon) Write a program that prompts the user to enter the length from the center of a pentagon to a vertex and computes the area of the pentagon, as shown in the following figure. The formula for computing the area of a pentagon is Area = 5 times s^2/4 times tan(pi/5), where s is the length of a side. The side can be computed using the formula s = 2r sin pi/5, where r is the length from the center of a pentagon to a vertex. Round up two digits after the decimal point. Here is a sample run:Explanation / Answer
HI, Please find my implementation.
import java.util.Scanner;
public class PentagoanArea {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the length from center to vertex: ");
double r = sc.nextDouble();
double s = 2*r*Math.sin(Math.PI/5);
double area = (5*s*s)/(4*Math.tan(Math.PI/5));
System.out.println("The are of the pentagoan is: "+String.format("%.2f", area));
//System.out.println("The are of the pentagoan is: "+area);
}
}
/*
Sample run:
Enter the length from center to vertex: 5.5
The are of the pentagoan is: 71.92
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.