Question: Exercise 8.4 JHTP (Rectangle Class): Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide methods that calculate the
Exercise 8.4 JHTP (Rectangle Class): Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide methods that calculate the rectangles perimeter and area. Use set and get methods for both length and width. The set methods will 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.
1. In the test class write code to create and print a menu that returns a value corresponding to the menu choice.

2. Also in the test file, remember to code a Try Catch Illegial Argument Expection to determine if the user entered a length and width of 0.0-20.
The user is supposed to input the values of the length and width and then the area and perimeter will be calculated. I have most of the code typed out but I am having a problem finishing the RectangleTest code. I do not know how to finish the catch argument so it will call the IllegalArgumentException from the Rectangle class, telling the user that the "Length/width must be between 0 and 20." I do not know if I need to add anything to that class in order to do that.
I know that other questions like this have been posted but the code has not given me what I needed, I need everything that is laid out in the instructions, I think I have most of it I just need help finishing it. Thank you!
This is what I have so far:
public class Rectangle { private float length, width; public Rectangle(){ this.length = (float) 1.0; this.width = (float) 1.0; } // Method to set length public void setLength(float length){ if (length20.0) this.length = length; else throw new IllegalArgumentException("Length must be between 0.0 and 20.0"); } // Method to retrive length public float getLength(){ return length; } // Method to set width public void setWidth(float width){ if (width>0.0 && width
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
