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

Implement the compare method of the following class RectangleComparator. The met

ID: 668385 • Letter: I

Question

Implement the compare method of the following class RectangleComparator. The method compares two rectangles. The method should return: A positive integer if the area of the first rectangle is larger than the area of the second rectangle A negative integer if the area of the first rectangle is smaller than the area of the second rectangle 0 if the two rectangles have the same area.

import java.util.Comparator;

import java.awt.Rectangle;

public class RectangleComparator implements Comparator<Rectangle>

`{   

/** Compares two Rectangle objects.

@param r1 the first rectangle

@param r2 the second rectangle

@return 1 if the area of the first rectangle is larger than the area of

the second rectangle, -1 if the area of the first rectangle is

smaller than the area of the second rectangle or 0 if the two

rectangles have the same area

*/

public int compare(Rectangle r1, Rectangle r2)

{ ...

}

}

Explanation / Answer

}