Question: For Java- Using the Rectangle class you created previously to create a second class called RectangleComparator that implements the Comparator interface to compares two Rectangle

For Java-

Using the Rectangle class you created previously to create a second class called RectangleComparator that implements the Comparator interface to compares two Rectangle objects according to area.

Create a third class called RectangleSortTest that contains the main method. The method should create a List containing five Rectangle objects, not in order by area. The method should print the list, displaying each rectangles area. Then sort the list, and print the list again showing the list has been sorted by area. This test class does not need to ask users for input, nor does it need to do any additional error checking.

Previous code:

public class Rectangle { private double width; private double height; public Rectangle (double width, double height) { this.width = width; this.height = height; } public double getWidth(){ return width; } public void setWidth(double width){ this.width = width; } public double getHeight(){ return height; } public void setHeight(double height){ this.height = height; } public double calculateArea() { return height*width; } public double calculatePerimeter() { return 2*(height+width); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!