package candy; /** * A candy machine that provides two units of candy for every one provided * by a base machine. * * @author CSC223 2004F * @version 0.5 of September 2004 */ public class DoubleCandyMachine implements CandyMachine { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** * The base candy machine from which this draws candy. */ CandyMachine base; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ public DoubleCandyMachine(CandyMachine base) { this.base = base; } // DoubleCandyMachine(CandyMachine) // +----------+---------------------------------------------------------- // | Mutators | // +----------+ /** * Usually get twice as much candy as in previous machines. */ public String get() throws CandyMachineException { String tmp = base.get(); if (base.isEmpty()) return tmp; else return tmp + " and " + base.get(); } // get() // +-----------+--------------------------------------------------------- // | Observers | // +-----------+ /** * Determine if the candy machine is empty. */ public boolean isEmpty() { return base.isEmpty(); } // isEmpty() } // class DoubleCandyMachine