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

Based on the compareTo method for Circle objects below: public int compareTo (Ci

ID: 3761863 • Letter: B

Question

Based on the compareTo method for Circle objects below:

public int compareTo (Circle circle)

//precondition: circle !=null

{

if (this.radius < circle.radius)

return -1;

else

if (this.radius == circle.radius)

return 0;

else

return 1;

}

What is the output of the following code sequence?

Circle c1 = new Circle (5);

Circle c2 = new Circle (5);

Circle c3 = new Circle (15);

System.out.println(c1.compareTo(c1));

System.out.println(c1.compareTo(c2));

System.out.println(c2.compareTo(c3));

System.out.println(c3.compareTo(c2));

Explanation / Answer

0; //since c1 radius is same as c1

0; since c1 and c2's radius is same

1; since c3 and c2's radius is not same

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote