Question: Part I: Create a class named Rectangle.java with attributes length and width (both should be defined as double), each of which defaults (non-parameter constructor) to

Part I:

Create a class named Rectangle.java with attributes length and width (both should be defined as double), each of which defaults (non-parameter constructor) to 1.0. The second constructor should accept the length and width as as arguments to initialize a Rectangle's length and width fields. Provide methods that calculate the rectangle's perimeter and area. 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 50.0. Provide toString method that returns its rectangle information in the format as shown below:

[length: 2.00, width: 2.00, Perimeter: 8:00, area: 4.00 ]

methods headers:

public double perimeter()

public double area()

Part II:

Write a program called RectangleDriver.java to test Rectangle class with the following code (simply copy the following code into your main method):

Rectangle rec=new Rectangle(1.0, 5.0);

Rec.setLength(-2.50);

System.out.println(rec);

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