virtual void turnCrank() { std::cout << "You turned..." << std::endl; int winner = rand() % 5; // randomWinner->nextInt(10); if ((winner == 0) && (gumballMachine->getCount() > 1)) { gumballMachine->setState(gumballMachine->getWinnerState()); } else { gumballMachine->setState(gumballMachine->getSoldState()); } }
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()); } } }
public: virtual void insertQuarter() { std::cout << "You inserted a quarter" << std::endl; gumballMachine->setState(gumballMachine->getHasQuarterState()); }
virtual void ejectQuarter() { std::cout << "Quarter returned" << std::endl; gumballMachine->setState(gumballMachine->getNoQuarterState()); }
void insertQuarter() const { std::cout << "You inserted a quarter" << std::endl; _gumballMachine->setState(_gumballMachine->getHasQuarterState()); }