Question: A java program that allows a user to create and display rectangle objects. You should write your own Rectangle class for this purpose. Your program
A java program that allows a user to create and display rectangle objects. You should write your own Rectangle class for this purpose. Your program should have the following main menu:
## Rectangle Program ##
1. Enter rectangle details
2. Show all rectangles
3. Exit program
Ifoption 1is selected: Ask the user for a length in centimetres (a float) and a width in centimetres (a float) to creating a new rectangle. If the rectangle is successfully created, add it to an ArrayList and report a success message back to the user before re-showing the menu above. If there was an error creating the rectangle (because the user entered non-numeric data or a negative value for the length or width), or if there was an error adding the rectangle to the list, report an appropriate message before re-showing the menu above.
Ifoption 2is selected: Print out the length, width and area of each rectangle to two decimal places, ordered byarea, so that details of the smallest rectangle will be printed first and details of the largest rectangle will be printed last (see example output below). Have your Rectangle class implement the Comparable interface to assist with this task.
Example output for this option:
Length: 2.14cm, Width: 3.57cm, Area: 7.64cm
Length: 3.99cm, Width: 5.11cm, Area: 20.39cm
Length: 5.0cm, Width: 13.4cm, Area: 67.00cm
Ifoption 3is selected: Terminate the program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
