// Rectangle.java // A rectangle class with methods move and contains public class Rectangle { // instance variables private int x0; private int y0; private int width; private int height; // constructors public Rectangle (int x, int y, int w, int h) { this.x0 = x; // "this." is optional unless the parameter this.y0 = y; // has the same name this.width = w; this.height = h; } // instance methods public void move(int dx, int dy) { x0 += dx; y0 += dy; } public boolean contains(int x, int y) { return (x >= x0 && x <= x0 + width && y >= y0 && y <= y0 + height); } public int getX() { return x0; } public int getY() { return y0; } }