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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started