/** * Author: Josiah Yoder et al. * Class: SE2811-011 * Date: 12/9/13 8:27 AM * Lesson: Week 2, Day 2 */ package example2_2; import java.awt.Point; import java.util.Scanner; public abstract class Duck { double topLeftX; double topLeftY; String name; SwimBehavior swimBehavior; public Duck(String name) { this.name = name; this.swimBehavior = new Floating(); } public Duck() { this("Anon."); } public static Duck createDuck(Scanner in){ return new Mallard(); } private Point getPosition() { return new Point((int)topLeftX, (int) topLeftY); } public void setSwimBehavior(SwimBehavior swimBehavior) { this.swimBehavior = swimBehavior; } private void setPosition(Point point) { topLeftX = point.getX(); topLeftY = point.getY(); } public void quack() { } public void swim() { setPosition(swimBehavior.swim(getPosition())); } public void display() { System.out.println("The duck "+name+ " is at ("+topLeftX+", "+topLeftY +")"); } }