union
that will be placed inside the Rectangle
class. The method accepts another rectangle r as a parameter and turns the current rectangle into the union of itself and r; that is, modifies the fields so that they represent the smallest rectangular region that completely contains both this rectangle and r.
Rectangle rect1 = new Rectangle(5, 12, 4, 6); Rectangle rect2 = new Rectangle(6, 8, 5, 7); Rectangle rect3 = new Rectangle(14, 9, 3, 3); Rectangle rect4 = new Rectangle(10, 3, 5, 8); rect1.union(rect2); // {(5, 8), 6x10} rect4.union(rect3); // {(10, 3), 7x9}