Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class named Rectangle to represent a rectangle. The class contains: ? T

ID: 3640704 • Letter: D

Question

Design a class named Rectangle to represent a rectangle. The class contains:
? Two double data fields named width and height that specify the width and height of the rectangle.
? A no-arg constructor that creates a default rectangle.
? A constructor that creates a rectangle with the specified width and height.
? A method named getArea() that returns the area of this rectangle.
? A method named getPerimeter() that returns the perimeter.

Write a test program that creates two Rectangle objects—one with width 4 and height 40 and the other with width 3.5 and height 35.9. For the first object, assign the values using the dot operator. For the second object, pass the dimension values as parameters. Display the width, height, area, and perimeter of each rectangle in this order.

Explanation / Answer

package mundo; public class Rectangle { private double width; private double height; public Rectangle() { width = 10; height = 5; } public Rectangle(double pWidht, double pHeight) { width = pWidht; height = pHeight; } public double getArea() { double area = width * height; return area; } public double getPerimeter() { double perimeter = 2*width +2*height; return perimeter; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote