package example2_2; import java.util.Scanner; /** * Author: Josiah Yoder et al. * Class: SE1011-011 * Date: 12/10/13 8:25 AM * Lesson: Week 7, Day 1 */ public class DuckFactory { public static final int NO_DUCK = Integer.MAX_VALUE; public static final int FINISHED = 0; public static final int MALLARD = 1; public static final int DARKWING_DUCK = 2; public Duck createDuck(int duckType, Scanner in) { Duck newDuck = null; if (duckType == MALLARD) { Mallard.createDuck(in); } else if (duckType == DARKWING_DUCK) { DarkWingDuck.createDuck(in); } else if (duckType == FINISHED ) { newDuck = null; // Ensure duck is not added twice. /* Loop will exit automatically. */ } else { System.out.println("Warning: Unknown duck type. No duck created."); } return newDuck; } }