Consider the following data-type implementation for axis-aligned rectangles, which represents each rectangle with the coordinates of its center point and its width and height:
public class Rectangle{ private final double x, y; // center of rectangle private final double width; // width of rectangle private final double height; // height of rectangle public Rectangle(double x0, double y0, double w, double h) { x = x0; y = y0; width = w; height = h; } public double area() { return width * height; } public double perimeter() { /* Compute perimeter. */ } public boolean intersects(Rectangle b) { /* Does this rectangle intersect b? */ } public boolean contains(Rectangle b) { /* Is b inside this rectangle? */ } public void draw(Rectangle b) { /* Draw rectangle on standard drawing. */ }}
Write an API for this class, and fill in the code for perimeter(), intersects(), and contains(). Note: Consider two rectangles to intersect if they share one or more common points (improper intersections). For example, a.intersects(a) and a.contains(a) are both true.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.