import java.awt.geom.Point2D; import java.util.Objects; public class SurfaceRectangle implements Surface { private double x, y, width, height; public SurfaceRectangle(double x, double y, double width, double height) { this.x = x; this.y = y; this.width = width; this.height = height; } @Override public boolean contains(Point2D p) { return p.getX() >= x && p.getY() >= y && p.getX() - x <= width && p.getY() - y <= height; } @Override public boolean areConnected(Point2D p1, Point2D p2) { return contains(p1) && contains(p2); } public boolean equals(Object o) { if (! (o instanceof SurfaceRectangle)) return false; SurfaceRectangle r = (SurfaceRectangle)o; return x == r.x && y == r.y && width == r.width && height == r.height; } public int hashCode() { return Objects.hash(x, y, width, height); } }