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

public class Rectangle extends Shape { private Point lowerLeft, upperRight; Rect

ID: 3694175 • Letter: P

Question

public class Rectangle extends Shape {

   private Point lowerLeft, upperRight;

   Rectangle(Point lowerLeft, Point upperRight) {

      this.lowerLeft = lowerLeft;

      this.upperRight = upperRight;

   }

   @Override

   public double computeArea() {

      double length = 0.0;

      double height = 0.0;

    length = upperRight.getX() - lowerLeft.getX();

      height = upperRight.getY() - lowerLeft.getY();

      return (length * height);

   }

}

Extend this so that there is the following public method: boolean isSquare(): returns true if the rectangle is a square, false otherwise

Explanation / Answer

public class Rectangle extends Shape {

private Point lowerLeft, upperRight;

Rectangle(Point lowerLeft, Point upperRight) {
this.lowerLeft = lowerLeft;
this.upperRight = upperRight;
}

@Override
public double computeArea() {
double length = 0.0;
double height = 0.0;

length = upperRight.getX() - lowerLeft.getX();
height = upperRight.getY() - lowerLeft.getY();

return (length * height);
}
public boolean isSquare()
   {
       double length = 0.0;
double height = 0.0;

length = upperRight.getX() - lowerLeft.getX();
height = upperRight.getY() - lowerLeft.getY();
  
   if(length==height)
       return true;
   else
       return false;
  
   }
}