checking if a point is inside a specified Rectangle

AWT Rectangle already has contains method. ( link )

Task seems about if you understand how naming spaces conflict. For example, if you are lazy (it's one of most admired qualities of a programmer), then you can write:

public static class Rectangle {
    java.awt.Rectangle _r;

    public Rectangle(int x, int y) {
        this._r = new java.awt.Rectangle(x, y);
    }
    public boolean contains(Point p) {
        return this._r.contains(p);
    }
}

You generally do not want to reimplementing features nor extend classes.


It looks ok to me. I would check that your test case actually has the numbers you think it does; I would also check that your accessors are all returning the right values (I can't tell you the number of times I've implemented getX() as {return this.y;}). Other than that it's anyone's guess.

Tags:

Java

Geometry