Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question #2 25 point eate a testing class which will create two RegularPolygon o

ID: 3882099 • Letter: Q

Question

Question #2 25 point eate a testing class which will create two RegularPolygon objects and if the two objecta are the objects are not the same then copy all the information from the second object into the first one same display then display a message stating both objects contain the same information. It the Ewo Do not assign the objects. You need to copy all the information from second object into the first one. You wil1 need to create two more methods in the RegularPolygon class: equals checks if the information of two objects are the same copy copies the information of one object into another 25 poi

Explanation / Answer

Hi Friend, you have not posted class.

Si i created my own class and implemented methods.

public class RegularPolygon {

   private int numSides;

   private int sideLength;

   public RegularPolygon(int numSides, int sideLength) {

       this.numSides = numSides;

       this.sideLength = sideLength;

   }

   public void setNumSides(int numSides) {

       this.numSides = numSides;

   }

   public int getNumSides() {

       return numSides;

   }

   public void setSideLengths(int sideLength) {

       this.sideLength = sideLength;

   }

   public int getSideLengths() {

       return sideLength;

   }

  

  

   public boolean equals(RegularPolygon obj) {

       if(numSides == obj.numSides && sideLength == obj.sideLength)

           return true;

       else

           return false;

   }

  

   public void copy(RegularPolygon obj1, RegularPolygon obj2) {

       obj1.numSides = obj2.numSides;

       obj1.sideLength = obj2.sideLength;

   }

  

   public static void main(String[] args) {

      

       RegularPolygon obj1 = new RegularPolygon(5, 6);

       RegularPolygon obj2 = new RegularPolygon(5, 6);

      

       if(obj1.equals(obj2))

           System.out.println("both are equal");

      

       RegularPolygon obj3 = new RegularPolygon(2, 3);

      

       obj3.copy(obj1, obj3);

      

       System.out.println("obj1: "+obj1.numSides+", "+obj1.sideLength);

   }

  

}

/*

Sample run:

both are equal

obj1: 2, 3

*/