void dispense() { std::cout << "YOU'RE A WINNER! You get two gumballs for your quarter" << std::endl; _gumballMachine->releaseBall(); if (_gumballMachine->getCount() == 0) { _gumballMachine->setState(_gumballMachine->getSoldOutState()); } else { _gumballMachine->releaseBall(); if (_gumballMachine->getCount() > 0) { _gumballMachine->setState(_gumballMachine->getNoQuarterState()); } else { std::cout << "Oops, out of gumballs!" << std::endl; _gumballMachine->setState(_gumballMachine->getSoldOutState()); } } }
virtual void ejectQuarter() { std::cout << "Quarter returned" << std::endl; gumballMachine->setState(gumballMachine->getNoQuarterState()); }