package ballworld; import cs101.lang.Animate; /** * The Dud object is a very simple implementation of the Ball interface. * Its location changes only in response to user clicks, and its radius * is constant at 5. */ public class Dud implements Ball, Animate { private double x; // The current X-coordinate of this Ball private double y; // The current Y-coordinate of this Ball private World myWorld; // The world in which this Ball resides /** * Returns current X-coordinate of this Ball. */ public double getX() { return this.x; } /** * Returns current Y-coordinate of this Ball. */ public double getY() { return this.y; } /** * Returns 5. */ public double getRadius() { return 5; } /** * Sets the world in which this ball resides to be "theWorld". */ public void setWorld(World theWorld) { this.myWorld = theWorld; } /** * Moves this Ball to the location at which the user clicked. */ public void userClicked(double atX, double atY) { this.x = atX; this.y = atY; } /** * If the user typed a 'd', removes this Ball from myWorld. Otherwise * ignores the keypress. */ public void userTyped(char key) { if (key == 'd') { this.myWorld.removeBall(this); } else { // Ignore keypress } } /** Does nothing. */ public void act() { } }