Question: AP Computer Science A Instructions Write a Java code which takes inputs and creates two RegularPolygon objects (using the shapes.RegularPolygon class) and compares them using
AP Computer Science A
Instructions
Write a Java code which takes inputs and creates two RegularPolygon objects (using the shapes.RegularPolygon class) and compares them using the equals method.
The first RegularPolygon should use a single user input and the single-parameter constructor RegularPolygon(double len) making an equilateral triangle with side length len. The second RegularPolygon should use two user inputs and the second RegularPolygon constructor. The code should then check the two objects for equality, printing "Congruent Regular Polygons!" if they are identical according to the RegularPolygon equals method and "Different Regular Polygons" if they are not the same.
Sample run 1:
Enter the side length of the first regular polygon: 2 Enter the number of sides of the second polygon: 3 Enter the side length of the second polygon: 2 Congruent Regular Polygons!
Sample run 2:
Enter the side length of the first regular polygon: 2 Enter the number of sides of the second polygon: 4 Enter the side length of the second polygon: 2 Different Regular Polygons
Sample run 3:
Enter the side length of the first regular polygon: 2 Enter the number of sides of the second polygon: 3 Enter the side length of the second polygon: 3 Different Regular Polygons
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
