Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 4, Problem 4.1PE

(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.

Chapter 4, Problem 4.1PE, (Geometry: area of a pentagon) Write a program that prompts the user to enter the length from the , example  1

The formula for computing the area of a pentagon is A r e a = 5 × s 2 4 × tan ( π 5 ) , where s is the length of a side. The side can be computed using the formula s = 2r sin π 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:

Chapter 4, Problem 4.1PE, (Geometry: area of a pentagon) Write a program that prompts the user to enter the length from the , example  2

Expert Solution & Answer
Check Mark
Program Plan Intro

Geometry: Area of the pentagon

Program Plan:

  • Import required packages.
  • Declare the main class method “pentagon”.
    • In the main method.
      • Create an object “in1” for the scanner class.
      • Get length from the user.
      • Declare the required variables for area of pentagon.
      • Calculate the area of the pentagon.
      • Display the pentagon.
Program Description Answer

The below program reads length and display the area of the pentagon.

Explanation of Solution

Program:

//import the required header files

import java.util.Scanner;

//create a class "pentagon"

public class pentagon

{

//main function   

public static void main(String[] args)

{

//Create an object

Scanner in1 = new Scanner(System.in);

//Get length from user

System.out.print("Enter the length from the center to a vertex: ");

//Get the length in "double" type

double r1 = in1.nextDouble();

//Calculate "s1"

double s1 = 2 * r1 * Math.sin(Math.PI / 5);

//Calculate "a1"

double a1 = 5 * s1 * s1 / (4 * Math.tan(Math.PI / 5));

//Display "area"

System.out.println("The area of the pentagon is " +

Math.round(a1 * 100) / 100.0);

}

}

Sample Output

Enter the length from the center to a vertex: 5.5

The area of the pentagon is 71.92

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
What does the following code snippet do?
What is printed by the following code? Please explain I’m confused
What is the output of the following code segment?

Chapter 4 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)

Ch. 4.3 - Evaluate the following: Int i = '1'; int j ='1' +...Ch. 4.3 - Can the following conversions involving casting be...Ch. 4.3 - Show the output of the following program: public...Ch. 4.3 - Write the code that generates a random lowercase...Ch. 4.3 - Show the output of the following statements:...Ch. 4.4 - Suppose s1, s2, and s3 are three strings, given as...Ch. 4.4 - Prob. 4.4.2CPCh. 4.4 - Show the output of the following statements (write...Ch. 4.4 - Prob. 4.4.4CPCh. 4.4 - Let s1 be " Welcome " and s2 be " welcome ". Write...Ch. 4.4 - Write one statement to return the number of digits...Ch. 4.4 - Write one statement to return the number of digits...Ch. 4.5 - If you run Listing 4.3 GuessBirthday.java with...Ch. 4.5 - If you enter a lowercase letter such as b, the...Ch. 4.5 - What would be wrong if lines 6 and 7 are in...Ch. 4.6 - Prob. 4.6.1CPCh. 4.6 - Prob. 4.6.2CPCh. 4.6 - Show the output of the following statements: (a)...Ch. 4 - (Geometry: area of a pentagon) Write a program...Ch. 4 - (Geometry: great circle distance) The great circle...Ch. 4 - (Geography: estimate areas) Use the GPS locations...Ch. 4 - (Geometry: area of a hexagon) The area of a...Ch. 4 - (Geometry: area of a regular polygon) A regular...Ch. 4 - (Random points on a circle) Write a program that...Ch. 4 - (Corner point coordinates) Suppose a pentagon is...Ch. 4 - (Find the character of an ASCII code) Write a...Ch. 4 - (Find the Unicode of a character) Write a program...Ch. 4 - (Guess birthday) Rewrite Listing 4.3,...Ch. 4 - (Decimal to hex) Write a program that prompts the...Ch. 4 - (Hex to binary) Write a program that prompts the...Ch. 4 - (Vowel or consonant?) Write a program that prompts...Ch. 4 - (Convert Letter grade to number) Write a program...Ch. 4 - (Phone key pads) The international standard...Ch. 4 - (Random character) Write a program that displays a...Ch. 4 - (Days of a month) Write a program that prompts the...Ch. 4 - (Student major and status) Write a program that...Ch. 4 - (Business: check ISBN-10) Rewrite Programming...Ch. 4 - (Process a string) Write a program that prompts...Ch. 4 - (Check SSN) Write a program that prompts the user...Ch. 4 - (Check substring) Write a program that prompts the...Ch. 4 - 23 (Financial application: payroll) Write a...Ch. 4 - (Order three cities) Write a program that prompts...Ch. 4 - (Generate vehicle plate numbers) Assume that a...Ch. 4 - (Financial application: monetary units) Rewrite...
Program to find HCF & LCM of two numbers in C | #6 Coding Bytes; Author: FACE Prep;https://www.youtube.com/watch?v=mZA3cdalYN4;License: Standard YouTube License, CC-BY