title: Check if rectangles overlap in MyRectangle2D.java class
body: <p>My assignment is to check if two points are inside a rectangle, check if a rectangle is inside another rectangle, and also check if a rectangle overlaps another rectangle</p>
  
  <p>I completed the first two steps but I can't solve the overlapping method.</p>
  
  <p>This what I've done.</p>
  
  <pre><code>public class MyRectangle2D {
      public static void main(String[] args) {
  
          Scanner input = new Scanner(System.in);
          MyRectangle2D rect = new MyRectangle2D();
  
          //returns area of default rectangle
          System.out.println(rect.getArea());
  
          //returns perimeter of default rectangle
          System.out.println(rect.getPerimeter());
  
          //returns true if default (0,0) is inside rectangle
          System.out.println(rect.contains(0,0));
  
          //returns false if point is not in triangle
          System.out.println(rect.contains(10,10));
  
          MyRectangle2D r1 = new MyRectangle2D(10,2,6,4);
          System.out.println("The area of your rectangle is " + r1.getArea() + 
              " \nthe perimeter of your rectangle is " + r1.getPerimeter());
  
          System.out.println("Testing Rectangle 2 with points (1,8)...");
  
          //following lines test the contain(x,y) method
          System.out.println(r1.contains(1,8) ? "Point (1,8) is on Rectangle" : "Point(1,8) is not on Rectangle");
  
          System.out.println("Testing Rectangle 2 with points (10,1)...");
  
          System.out.println(r1.contains(10,1) ? "Point (10,1) is on Rectangle" : "Point(10,1) is not on Rectangle");
  
          //following lines test contains(rect) method
          System.out.println(r1.contains(new MyRectangle2D(9,1,1,1)) ? "Rectangle is inside" : "Not inside");
          System.out.println(r1.contains(new MyRectangle2D(9,1,10,2)) ? "Rectangle is inside" : "Rectangle is not inside");
  
          //following lines test if rectangles overlap
          System.out.println(r1.overlaps(new MyRectangle2D(4,2,8,4)));
      }
  
      double x;
      double y;
      double width;
      double height;
  
      private MyRectangle2D(){
          x = 0;
          y = 0;
          width = 1;
          height = 1;
      }
  
      private MyRectangle2D(double newX, double newY, 
               double newWidth, double newHeight){
           setX(newX);
           setY(newY);
           setHeight(newHeight);
           setWidth(newWidth);
       }
  
      double getX(){
          return x;
      }
  
      double getY(){
          return y;
      }
  
      void setX(double newA){
          x = newA;
      }
  
      void setY(double newA){
          y = newA;
      }
  
      double getWidth(){
          return width;
      }
  
      double getHeight(){
          return height;
      }
  
      void setWidth(double newA){
          width = newA;
      }
  
      void setHeight(double newA){
          height = newA;
      }
  
      double getArea(){
          double area = width * height;
          return area;
      }
  
      double getPerimeter(){
          double perimeter = (2 * width) + (2 * height);
          return perimeter;
      }
  
      boolean contains(double x, double y){
          boolean inside = false;
          if(x&lt;(getWidth()/2 + getX()) &amp;&amp; x&gt;getX()-(getWidth()/2)){
              if(y&lt;(getY() + getHeight()/2) &amp;&amp; y&gt;getY()-(getHeight()/2))
              inside = true;
          }
          return inside;
      }
  
      boolean contains(MyRectangle2D r){
          boolean inside = false;
          if(r.getX()&lt;(getWidth()/2 + getX()) &amp;&amp; r.getX()&gt;getX()-(getWidth()/2)){
              if(r.getY()&lt;(getY() + getHeight()/2) &amp;&amp; r.getY()&gt;getY()-(getHeight()/2)){
                  if(r.getWidth()&lt;=getWidth() &amp;&amp; r.getHeight()&lt;=getHeight())
                  inside = true;
              }   
          }   
          return inside;
      }
  
      boolean overlaps(MyRectangle2D r){
          boolean inside = false;
          if(contains(r.getX()+r.getWidth(),r.getY()+r.getHeight()))
          inside = true;
  
          if(contains(r.getX()-r.getWidth(),r.getY()-r.getHeight()))
          inside = true;
          return inside;
  
      }
  
  }
  </code></pre>