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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.