Question: Hello, I would like to solve these two questions now, please, with details (The Rectangle class) Design a class named Rectangle to calculate the area

Hello, I would like to solve these two questions now, please, with details

(The Rectangle class)

Design a class named Rectangle to calculate the area and perimeter of a rectangle.

Declare a class Rectangle with the following attributes:

  • Double data field named width that specifies the width of the rectangle.
  • Double data field named height that specifies the height of the rectangle. The default values are 1 for both width and height.
  • The class Rectangle must have the following constructors:
    • A no-arg constructor that creates a default rectangle.
    • A constructor that creates a rectangle with the specified width and height.
  • The class Rectangle must have the following behaviors:
    • Two setting methods for width and height.
    • Two getting methods for width and height.
    • A method named getArea() that returns the area of this rectangle.
    • A method named getPerimeter() that returns the perimeter of this rectangle.
    • A method named toString() that return the rectangle information.

Implement class RectangleTest that demonstrates class Rectangles capabilities.

Write a test program that creates two Rectangle objects:

  1. Rectangle with width 4 and height 40
  2. Rectangle with width 3.5 and height 35.9.

Display the width, height, area, and perimeter of each rectangle in this order. (as shown in the output sample)

Sample Output:

Hello, I would like to solve these two questions now, please, with

run: Rectangle No. 1 width = 4.0 Hight = 40.0 Area = 160.0 Perimeter = 88.0 Rectangle No. 2 width = 3.5 Hight = 35.9 Area = 125.64999999999999 Perimeter = 78.8 BUILD SUCCESSFUL (total time: 3 seconds)

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!