Question: Using theRectangle class you created in Chapter 8's programming assignment, create a second class calledRectangleComparator that implements theComparator interface to compares twoRectangle objects according to

Using theRectangle class you created in Chapter 8's programming assignment, create a second class calledRectangleComparator that implements theComparator interface to compares twoRectangle objects according to area.

Create a class calledRectanglecontaining the following:

  • Two instance variables,
    • An instance variable of typedouble used to hold the rectangle's width.
    • An instance variable of typedouble used to hold the rectangle's height.
  • Provide a constructor with two parameters used to initializes each instance variable. The constructor shouldverify that the specified width and height values are greater than0.0 and less than or equal to20.0. If they are not, indicate an exception has occurred.
  • Provide get methods that return the values of each instance variables.
  • Provide set methods that set the instance variables to new values. The methods should also verify that thespecified width and height values are greater than0.0 and less than or equal to20.0. If they are not, indicate an exception has occurred.
  • Provide a method calledcalculatePerimeter that calculates the perimeter of the rectangle and return that value as adouble.
  • Provide a method calledcalculateArea that calculates the area of the rectangle and returns that value as adouble.

Create a third class calledRectangleSortTest that contains themain method. The method should create aList containing fiveRectangle objects, not in order by area. The method should print the list, displaying each rectangle's 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.

also Create the Pseudocode

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 Programming Questions!