Problem

Develop an implementation of your Rectangle API from EXERCISE 3.2.1 that represents rectan...

Develop an implementation of your Rectangle API from EXERCISE 3.2.1 that represents rectangles with the x- and y-coordinates of their lower-left and upper-right corners. Do not change the API.

EXERCISE 3.2.1

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.

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 3.2