Hey everyone. I am working on a hw assignment where I have to create a class called Rectangle that is utilized in another program. The end result is a graphic of colored rectangles, which overlap in certain areas and change color where they overlap. I have to create a method called overlapWith that checks to see if two rectangles overlap.

if (redRect.overlapsWith(greenRect)) {

Rectangle overlap = redRect.getOverlap(greenRect);

overlap.draw(page);

This piece of code is from the program that utilizes the overlapsWith method I am trying to create. redRect and greenRect were rectangles that were previously defined. This is from my hw assignment: the overlapsWith method should return whether or not the rectangle you call it on (this) overlaps with another rectangle (the argument). Here's a strategy for checking if this rectangle overlaps with another:

If the left x of this rectangle is larger than the right x of the other (or vice versa), they don't overlap.

If the top y of this rectangle is larger than the bottom y of the other (or vice versa), they don't overlap.

Otherwise, they do overlap.

I am stuck and do not know how to start this method. How do I compare x,y data from two seperate variables? Any help would be appreciated.