Drawing Multiple Polygons using java with comments In the ma

Drawing Multiple Polygons, using java, with comments.

In the manyPolygons methods,  write the code to have the turtle draws the specified number of regular polygons, each starting at the same place, however,
after each polygon is drawn the turtle turns 360.0 / numPolys degrees.

Some calls to manyPolygons to try out:

manyPolygons(t, 45, 3, 100)

manyPolygons(t, 60, 30, 20)

Solution

class Example{}

class HashCodeDemo
{
   public static void main(String[] args)
   {
       Example e1 = new Example();
       Example e2 = new Example();

       System.out.println(e1.hashCode()); //1671711
       System.out.println(e2.hashCode()); //11394033

       //Contract between equals() and hashCode() methods
       System.out.println(e1 == e2); //false
       System.out.println(e1.equals(e2)); //false
       System.out.println(e1.hashCode() == e2.hashCode()); //false

       Example e3 = e2;
       System.out.println(e2 == e3); //true
       System.out.println(e2.equals(e3)); //true
       System.out.println(e2.hashCode() == e3.hashCode()); //true

       //in the below case the above contract is failed, as equals() method in Student class compares state of the objects.
       Student s1 = new Student(1, \"Hari\");
       Student s2 = new Student(1, \"Hari\");
       System.out.println(s1.equals(s2)); //true
       System.out.println(s1.hashCode() == s2.hashCode()); //false

       //Conclusion
       //Hence if equals() method is overridden in sub class, hashCode() method should also be overriden.
       //If we do not override hashCode() it will not leads CE or RE, you face bussiness problems. You will not get correct results.
   }
}

Drawing Multiple Polygons, using java, with comments. In the manyPolygons methods, write the code to have the turtle draws the specified number of regular polyg

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site