package class1_3_DuckStrategies_v2; import java.awt.Point; /** * This class represents a specialized type of Duck * @author hornick */ public class Decoy extends Duck { /** * Decoy-specific constructor */ public Decoy(String name) { super(name,"decoy.jpg"); // this value defines how far the duck moves each update period - s random value between 1 and 3. increment = new Point(random.nextInt(3)+1, 0 ); } /** * This method OVERRIDES the Duck's default quacking behavior, * because Decoys don't make any sound. */ @Override public void quack() { // do nothing - Note same (duplicate) behavior implemented by RubberDuck } /** * This method OVERRIDES the Duck's default swimming behavior, * because Decoys only swim back and forth. */ @Override public void swim() { if( (currentPos.x > (DuckPond.PONDSIZE-image.getWidth(null))) // leaving the window's right edge || (currentPos.x < 0) ) { // ...or left edge increment.x = -increment.x; // reverse direction } currentPos.x += increment.x; // increment the position of the duck setLocation(currentPos); // ...and update its location in the container } }