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
(IN C LANGUAGE) Cumulative Addition: Computer selects a number between 7 and 23 at random. User will only add 2, 3 or 5 numbers to reach that number.For example: To reach 14: User will enter 5 5 2 2 (4 input).Also he can enter 2 2 2 2 2 2 2 (7 input) or 3 3 3 3 2 (5 input). https://www.bartleby.com/questions-and-answers/in-c-language-cumulative-addition-computer-selects-a-number-between-7-and-23-at-random.-user-will-on/0509c740-d993-44ed-a468-7e02da552600
(Financial: credit card number validation) Credit card numbers follow certain pat- terns. A credit card number must have between 13 and 16 digits. It must start with: 4 for Visa cards 5 for Master cards 37 for American Express cards 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or whether a credit card is scanned correctly by a scanner. Credit card numbers are generated following this validity check, commonly known as the Luhn check or the Mod 10 check, which can be described as follows (for illustra- tion, consider the card number 4388576018402626): 1. Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number. 4388576018402626 → 2 * 2 = 4 → 2 * 2 = 4 → 4 * 2 = 8 → 1 * 2 = 2 6 * 2 = 12 (1+ 2 = 3) → 5 * 2 = 10 (1+ 0 = 1) → 8 * 2 = 16 (1 + 6 = 7) → 4 * 2 = 8
(PYTHON) A Krishnamurthy number is a number which sum of the factorial of its digits is equal to the number itself. For example: Let us consider the number 145. Factorial sum = 1! + 4! + 5! = 1 + 24 + 120 = 145. Therefore 145 is a Krishnamurthy number. Other examples include: 1, 2, 40585. Write a program that does the following: • asks the user to input an integer. • computes whether the number is a Krishnamurthy number. • then finally prints the result. Note: You are not allowed to use the built-in function math.factorial.

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...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
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