Create a class Rectangle. The class has attributes length and width, each of which defaults to 1. It has methods that calculate the perimeter and the area of the rectangle. It has set and get methods for both length and width. The set methods should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0. Write a program to
test class Rectangle.
Name your testing class Assign8. Call JOptionPane.showInputDialog to get user input. Call JOptionPane.showMessageDialog to show the result or error.
Your class Rectangle is similar to Time1. Hint: Use Eclipse to generate get/set methods for the instance variables length and width.
In the two set methods throw IllegalArgumentExceltion if the input is beyond the valid range.
Add two more methods getPerimeter() and getArea(), in which call the get methods of length and width.
In Assign8 the main() method should keep prompting for input and show the result or error until the user clicks Cancel in the input dialog. Hint: Use while(true){...} loop and break it when JOptionPane.showInputDialog returns null.
You should catch IllegalArgumentExceltion and display error message. After that, keep prompting for input. Hint: put try/catch in the loop body.
When user enters a
string other than a number also display error message. Hint: When the input is invalid, Double.parseDouble() will throw NumberFormatException which is a subclass of IllegalArgumentExceltion. To catch it, put the statements inside the try block. Your catch(IllegalArgumentExceltion e) will catch from both Rectangle and Double classes.
I'm get stuck about it. Can anyone help me Thanks!
Here is my code so far: