public function dispense() { $this->gumballMachine->releaseBall(); if ($this->gumballMachine->getCount() > 0) { $this->gumballMachine->setState($this->gumballMachine->getNoQuarterState()); } else { println("Oops, out of gumballs!"); $this->gumballMachine->setState($this->gumballMachine->getSoldOutState()); } }
public function dispense() { println("YOU'RE A WINNER! You get two gumballs for your quarter"); $this->gumballMachine->releaseBall(); if ($this->gumballMachine->getCount() == 0) { $this->gumballMachine->setState($this->gumballMachine->getSoldOutState()); } else { $this->gumballMachine->releaseBall(); if ($this->gumballMachine->getCount() > 0) { $this->gumballMachine->setState($this->gumballMachine->getNoQuarterState()); } else { println("Oops, out of gumballs!"); $this->gumballMachine->setState($this->gumballMachine->getSoldOutState()); } } }