Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions