| ||You are searching for a new house. Location, location, location. You have
identified a number of desirable attributes, and for each have sketched a
rectangular area that contains all the locations that have that attribute.
You want it all. You need to find the area that is contained in every one of
your rectangles. Create a class Intersection that contains a method area that
takes as input the collection of rectangles and returns the area of
their common intersection.
The collection of rectangles is given by a int x and a int y. The first
two values of x and y specify opposing corners of one rectangle, the next two specify opposing corners of the next
rectangle, etc. Thus, each rectangle is the region between its two x values and between
its two y values.
|Method signature:||int area(int x, int y)|
|(be sure your method is public)|
|-||the 2 values of x (and of y) for a given rectangle are not necessarily given in ascending order|
|-||x contains an even number of elements between 2 and 50 inclusive|
|-||y contains the same number of elements as x|
|-||each element of x and y is between -10,000 and 10,000 inclusive|
|There are 2 rectangles, one having diagonally opposed corners (0,17) and (2,1000) and the other having diagonally opposed corners (3,18) and (-4,6).
The common intersection is the region bounded by x=0, x=2, y=17, y=18 which is
a rectangle 2 units wide and 1 unit tall.
|There is just one rectangle, so the answer is the area of that rectangle.|
|The first two rectangles intersect each other, and the second and third rectangles intersect each other, but no area is contained in all three rectangles. |
|Here we have 4 empty rectangles.|