Write 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

Respuesta :

The function that we use to check two object equality is if statement or conditional and we use Java.

The code is,

import java.util.*;

public class temp

{

 public static void main(String [] args)

 {

   Scanner s = new Scanner(System.in);

   double fn1, sn1, sn2;

   System.out.println("Enter the side length of the first regular polygon:");

   fn1 = double.parseDouble(s.nextLine());

   RegularPolygon fp = new RegularPolygon(fn1);

   System.out.println("Enter the number of sides of the second polygon:");

   sn1 = double.parseDouble(s.nextLine());

   System.out.println("Enter the side length of the second polygon:");

   sn2 = double.parseDouble(s.nextLine());

   RegularPolygon sp = new RegularPolygon(sn1, sn2);

   if(fp.equals(sp))

   {

     System.out.println("Congruent Regular Polygons!");

   }

   else

   {

     System.out.println("Different Regular Polygon.");

   }

 }

}

Variable of fn1 is used to contain input value for first polygon.

Variable of sn1 and sn2 is used to contain input value for second polygon.

Variable of fp is used to contain value of first polygon and sp is used to contain value of second polygon.

If statement is used to compare fp and sp for equality.

If two polygon equal then the print statement in body of if statement will run, if two polygon different then the print statement in body of else statement will run.

Learn more about if statement here:

brainly.com/question/17031764

#SPJ4