Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

List out some inventory management techniques.

Answered: 1 week ago