Question

Problem a (LA2a.java) Write a program to compute the area, perimeter, and interior angle of a...

Problem a (LA2a.java) Write a program to compute the area, perimeter, and interior angle of a regular polygon. First, have the user supply the number of sides of the polygon (a whole number, which must be 3 or greater) and the side length (any positive number). Then, compute the area via the following equation: where n is the number of sides and s is the side length. Note that the equations are equivalent, with the first using degrees and the second using radians. Then, compute the perimeter via the following equation: and then the interior angle (in degrees) via the following equation: So, an example run of your program would look like the following: (texts marked with blue color are the user’s input.) Enter number of sides: 3 Enter side length: 1 Area: 0.433 Perimeter: 3.000 Interior Angle: 60.000 degrees You should express the outputs using exactly three decimal places (rounding where necessary). Tips: (i) the Math.tan() method will compute the tangent of a value in radians, (ii) the Math.toRadians() method will convert a value in degrees to radians, and (iii) the Math.PI constant can be used for pi (π). Area = s2n 4tan( 180 n ) = s2n 4tan( ⇡ n ) Perimeter = ns Interior Angle = 180 360

*****Make sure error messages println in console and the program stops when less than 3 sides are entered or when negative numbers are entered

******make sure the word degrees is outputted after the value of Interior angle is given

Homework Answers

Answer #1

Program

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
   int n,s;
   double per,iAngle, area;
   Scanner in = new Scanner(System.in);
       System.out.print("Enter number of sides: ");
       n=in.nextInt();
       if(n<3)
       {
       System.out.println("Invalid sides");
       System.exit(0);
       }
       System.out.print("Enter side length:");
s=in.nextInt();
       if(s<1)
       {
       System.out.println("Invalid sides");
       System.exit(0);
       }
       double t=Math.toRadians(180/n);
       area= (s*s*n)/(4*Math.tan(t));
       per=n*s;
       iAngle= (n-2)*180/n;
   System.out.print("Area: "); System.out.format("%.3f", area);
   System.out.print("\nPerimeter: "); System.out.format("%.3f", per);
   System.out.print("\nInterior Angle: "); System.out.format("%.3f", iAngle); System.out.print(" degrees");
   }
      
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Design a Java class named Polygon that contains:  A private int data field named numSides...
Design a Java class named Polygon that contains:  A private int data field named numSides that defines the number of sides of the polygon. The default value should be 4.  A private double data field named sideLength that defines the length of each side. The default value should be 5.0.  A private double data field named xCoord that defines the x-coordinate of the center of the polygon. The default value should be 0.0.  A private double...
Write a complete recursive java program to compute the heights of the tick marks on a...
Write a complete recursive java program to compute the heights of the tick marks on a ruler. Assume that the length of the ruler is a power of 2 (say L=2^n, where n >=1) , and the marks are to be placed at every point between 0 and 2^n, not including the endpoints. The endpoints 0 and 2^n will have height 0. Here are the rules for computing the heights of the ticks for a ruler of length L=2^n: 1....
In C programming, Thank you Write a program to compute the area of a circle. You...
In C programming, Thank you Write a program to compute the area of a circle. You have to write a complete “C” program that compiles and runs in Codeblocks. Program requirements: 1. Declare the variables needed: radius (r) and area (yourLastName). 2. Calculate and print the area of each circle. 3. The program MUST prompt the user for a new radius (r) over and over until the user types -1. 5. Use the type double for all decimal numbers. 6....
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
c++ Program Description You are going to write a computer program/prototype to process mail packages that...
c++ Program Description You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list....
Chapter 19: Stair Framing and Finish Matching Match terms to their definitions. Write the corresponding letters...
Chapter 19: Stair Framing and Finish Matching Match terms to their definitions. Write the corresponding letters on the blanks. Not all terms will be used. 1. the entire stair rail assembly a. baluster 2. railing on a stairway intended to be grasped by the hand to serve as a support and guard b. balustrade c. handrail 3. upright post supporting the handrail in a flight of stairs d. newel post 4. vertical member of a stair rail, usually decorative and...
MATHEMATICS 1. The measure of location which is the most likely to be influenced by extreme...
MATHEMATICS 1. The measure of location which is the most likely to be influenced by extreme values in the data set is the a. range b. median c. mode d. mean 2. If two events are independent, then a. they must be mutually exclusive b. the sum of their probabilities must be equal to one c. their intersection must be zero d. None of these alternatives is correct. any value between 0 to 1 3. Two events, A and B,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT