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

Write a classcalled Rectangle that stores the length and width astype double . I

ID: 3618422 • Letter: W

Question

Write a classcalled Rectangle that stores the length and width astype double.  Include a constructor that acceptsboth length and width as formal parameters. Create instance methodsfor getting and setting the width and length ofthe Rectangle.  Write methods that will return theperimeter of theRectangle; calculate the areaof the Rectangle; a toString() methodthat returns a formatted String representation oftheRectangle; and anequals() methodthat accepts a Rectangle as a parameter and returns true if theargument has the same dimensions as the callingobject.

Explanation / Answer

please rate - thanks building upon the above post public class Rectangle {     private double _width = 0.0;     private double _length = 0.0;     public Rectangle(double dWidth,double dLength)     {         this._width =dWidth;         this._length =dLength ;     }     public void setWidth(double dWidth)     {         this._width =dWidth;     }     public double getWidth()     {         return this._width;     }      public void setlength (double dLength)     {         this._length =dLength ;     }     public double getlength ()     {         return this._length;     }     public double getPerimeter()     {         return2*(this._length+this._width);     }     public double getArea()     {         return (this._length *this._width);     }     @Override     public String toString()     {         return "Rectangle[width= "+this._width+", length = "+this._length+"]";     }     public boolean equals(Rectangle objRect)     {         if(this._length ==objRect.getlength() && this._width ==objRect.getWidth())            return true;         return false;     } public static void main(String[] args) {Rectangle a=new Rectangle(4,3); Rectangle b=new Rectangle(4,3); Rectangle c=new Rectangle(5,3); System.out.println( a.toString()); System.out.println("Area="+a.getArea()+"perimeter="+a.getPerimeter()); System.out.println(a.equals(b));    System.out.println(a.equals(c)); }   }

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