Question
Create a java program Polygon. In this program, you will have 4 public static methods: main, area, perimeter, and polyName. In the main method, get
Create a java program Polygon.
In this program, you will have 4 public static methods: main, area, perimeter, and polyName.
In the main method, get the user input for the number of sides of the polygon and the length of one side. Limit the number of sides to be between 3 and 10. Once you have this information, invoke the area and perimeter methods to get their return values and the polyName method to display the name of the polygon. After you have the returned information, display the area, and perimeter of the polygon. Use a loop to allow the user to continue entering information for different polygons until -1 is entered.
In the area method, there should be parameters for the number of sides and length. Calculate and return the area using the formula:
area = (number of sides * length of sides ^ 2)/ (4 * tan(pi/number of sides))
In the perimeter method, there should be parameters for the number of sides and length. Calculate and return the perimeter of the polygon.
In the polyName method, there should be a parameter for the number of sides. Use a switch statement to determine the name of the polygon. Display the name of the polygon and do not return any values to the main method.
Sample Output given 4 sides and a side length of 3:
Square 9 12
Extra Credit: Format output with aligned columns and column headings ("Polygon", "Area", "Perimeter").
PreviousNext
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started