Question: Problem 2: Polygons Write a program which asks the user for the following: length of a side (can be any real number) number of sides
Problem 2: Polygons Write a program which asks the user for the following: length of a side (can be any real number) number of sides (can only be an integer) length of apothem (real number, sort of like radius for a circle) Calculate the area using the formula: area = length of side * number of sides * length of apothem/2 Since area cannot be negative, ensure all answers are positive Hint: look up absolute value in the Math Javadoc Display the result Examples (when examples are given, be sure to test each example with your code) C:\java>java Polygons C:\java>java Polygons What is the length of a side? 10.0 What is the length of a side? -3.5 How many sides? 5 How many sides? 6 Length of apothem? 5.5 Length of apothem? 3.3 Area is: 137.5 Area is: 34.65
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
