# Class Rectangle

Class Rectangle : with length & width default to 1 , methods to calculate perimeter & area

, set & get for length & width , set verifies

floating pt number larger than 0.0 and less than 20.0

Sample Output:

Rectangle 1:

The length is : 1.000000

The width is : 1.000000

The perimeter is : 4.000000

The area is : 1.000000

Rectangle 2:

The length is : 2.000000

The width is : 1.000000

The perimeter is : 6.000000

The area is : 2.000000

Rectangle 3:

The length is : 2.000000

The width is : 2.000000

The perimeter is : 8.000000

The area is : 4.000000

Enter the length: .001

Enter the width: .001

Rectangle 4:

The length is : 0.001000

The width is : 0.001000

The perimeter is : 0.004000

The area is : 0.000001

Do you want to test an invalid length (1 for yes, 2 for no):

2

Do you want to test an invalid width(1 for yes, 2 for no): 1

testing: Rectangle r6 = new Rectangle(2,0);

Exception in thread "main"

java.lang.IllegalArgumentException: Width must be greater than 0.0 and less

than 20.0

at

Rectangle.<init(Rectangle.java:36)

at

RectangleTest.main(RectangleTest.java:91)

, set & get for length & width , set verifies

floating pt number larger than 0.0 and less than 20.0

Sample Output:

Rectangle 1:

The length is : 1.000000

The width is : 1.000000

The perimeter is : 4.000000

The area is : 1.000000

Rectangle 2:

The length is : 2.000000

The width is : 1.000000

The perimeter is : 6.000000

The area is : 2.000000

Rectangle 3:

The length is : 2.000000

The width is : 2.000000

The perimeter is : 8.000000

The area is : 4.000000

Enter the length: .001

Enter the width: .001

Rectangle 4:

The length is : 0.001000

The width is : 0.001000

The perimeter is : 0.004000

The area is : 0.000001

Do you want to test an invalid length (1 for yes, 2 for no):

2

Do you want to test an invalid width(1 for yes, 2 for no): 1

testing: Rectangle r6 = new Rectangle(2,0);

Exception in thread "main"

java.lang.IllegalArgumentException: Width must be greater than 0.0 and less

than 20.0

at

Rectangle.<init(Rectangle.java:36)

at

RectangleTest.main(RectangleTest.java:91)

You'll get 1 file (5.3KB)