Question: 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: Write
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:

Write an API for this class, and fill in the code for perimeter(), intersects (), and contains(). 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.
public class Rectangle { } private final double x, y; private final double width; private final double height; // center of rectangle // width of rectangle // height of rectangle public Rectangle (double x0, double y0, double w, double h) { X = x0; y = yo; 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. */ } representation height intersects contains (x, y) width a
Step by Step Solution
3.42 Rating (152 Votes )
There are 3 Steps involved in it
java public class Rectangle private final double x y center of rectangle private final double ... View full answer
Get step-by-step solutions from verified subject matter experts
