Class Name: Rectangles
Method Name: areOverlapping
Parameters: String, String
Returns: boolean
The method signature is (be sure your method is public):
boolean areOverlapping(String first, String second)
You are to implement a class Rectangles, which contains a method
areOverlapping. The method takes two rectangles and returns whether or not
they are overlapping.
In order for two rectangles to be considered overlapping, any of the four edges
of the first rectangle must intersect with any of the four edges of the second
rectangle in at least one point. If a corner, an entire side, or part of a
side is common between the two rectangles, then they are considered
overlapping. If one rectangle is completely enclosed within the other
rectangle, then they are not considered overlapping.
A rectangle is represented by a String. The String is structured as
"(x1,y1)-(x2,y2)". The " characters are not part of the String and there will
be no spaces in the String. x1, y1, x2 and y2 are each integers between -50
and 50 inclusive. The first digit of each number will be non-zero, unless the
number itself is equal to zero. If a number begins with a negative sign ('-'),
then the number following the negative sign will be non-zero.
(x1,y1) and (x2,y2) each represent a point on the Cartesian plane. Together
the points (x1,y1) and (x2,y2) define a rectangle. The point (x1,y1)
represents the top left corner of the rectangle, and the point (x2,y2)
represents the bottom right corner of the rectangle. TopCoder will ensure that
the data is structured properly, and that (x2,y2) resides below and to the
right of (x1,y1). TopCoder will also insure that x1, y1, x2, y2 are all
integers in the range of -50 and +50, inclusive.
Examples:
"(1,5)-(5,1)", "(2,6)-(6,2)" true
"(1,5)-(5,1)", "(1,5)-(5,1)" true
"(1,5)-(5,1)", "(10,11)-(11,10)" false
"(0,5)-(5,0)", "(2,3)-(3,2)" false
"(10,50)-(50,10)", "(1,10)-(10,1)" true
"(1,5)-(5,1)", "(0,1)-(6,0)" true
"(-10,10)-(10,-10)", "(-1,1)-(1,-1)" false