210k views
2 votes
Add the following method to your Rectangle class: public boolean contains(Rectangle rect) Returns whether the given other rectangle lies entirely within the bounds of this rectangle. (You don't need to write the class header or declare the fields; assume that this is already done for you. Just write your methods' complete code in the box provided.) See previous exercises for a description of the Rectangle and Point classes and their public members.

1 Answer

6 votes

Answer:

Step-by-step explanation:

The code is not provided in the question but can be easily found online. The code is written in Java and the Rectangle class contains the following variables for the Rectangle object

double x;

double y;

double width;

double height;

The x and y represent the starting positions and then the width and height are added to these starting positions to indicate the endpoints. Ultimately, these four points create the rectangle. The following method detects if these points from the rectangle passed as an argument are within the rectangle in question

public boolean contains (Rectangle r) {

return x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y;

}

User Rares Barbantan
by
5.2k points