We can use the following class for objects that are two-dimensional geometrical figures. The class includes a constructor to create an object representing a shape at some position in two-dimensional space. It also includes a method called translate that moves a shape to a new position relative to its current position.
0593: public class Shape { // Shape.java 0594: public Shape(int vX, int vY) { 0595: iX = vX; iY = vY; 0596: } 0597: public Shape() { this(0, 0); } 0598: public int getX() { return iX; } 0599: public int getY() { return iY; } 0600: public void translate(int vX, int vY) { iX += vX; iY += vY; } 0601: public boolean equals(Object rObject) { 0602: return iX == ((Shape) rObject).iX && iY == ((Shape) rObject).iY; 0603: } 0604: public String toString() { return iX + ":" + iY; } 0605: private int iX, iY; 0606: }