public void Dispense() { switch (_state) { case GumballMachineState.HasQuarter: Console.WriteLine("No gumball dispensed"); break; case GumballMachineState.NoQuarter: Console.WriteLine("You need to pay first"); break; case GumballMachineState.Sold: Console.WriteLine("Dispensing gumball..."); if (--_totalBalls == 0) { Console.WriteLine("Out of gumballs"); _state = GumballMachineState.SoldOut; } else { _state = GumballMachineState.NoQuarter; } break; case GumballMachineState.SoldOut: Console.WriteLine("No gumball dispensed"); break; } }
public void Dispense() { if (_state == GumballMachineState.Sold) { Console.WriteLine("A gumball comes rolling out the slot"); _count = _count - 1; if (_count == 0) { Console.WriteLine("Oops, out of gumballs!"); _state = GumballMachineState.SoldOut; } else { _state = GumballMachineState.NoQuarter; } } else if (_state == GumballMachineState.NoQuarter) { Console.WriteLine("You need to pay first"); } else if (_state == GumballMachineState.SoldOut) { Console.WriteLine("No gumball dispensed"); } else if (_state == GumballMachineState.HasQuarter) { Console.WriteLine("No gumball dispensed"); } }
public void Dispense() { if (_state == GumballMachineState.Sold) { _log.Append("A gumball comes rolling out the slot\n"); _count = _count - 1; if (_count == 0) { _log.Append("Oops, out of gumballs!\n"); _state = GumballMachineState.SoldOut; } else { _state = GumballMachineState.NoQuarter; } } else if (_state == GumballMachineState.NoQuarter) { _log.Append("You need to pay first\n"); } else if (_state == GumballMachineState.SoldOut) { _log.Append("No gumball dispensed\n"); } else if (_state == GumballMachineState.HasQuarter) { _log.Append("No gumball dispensed\n"); } }
public void StartWithQuarters(int count) { this._count = count; if (_count > 0) { _state = GumballMachineState.NoQuarter; } }
public GumballMachine(int count) { this._count = count; if (_count > 0) { _state = GumballMachineState.NoQuarter; } }
public GumballMachine(int totalBalls) { _totalBalls = totalBalls; if (_totalBalls > 0) { _state = GumballMachineState.NoQuarter; } }
public void EjectQuarter() { if (_state == GumballMachineState.HasQuarter) { Console.WriteLine("Quarter returned"); _state = GumballMachineState.NoQuarter; } else if (_state == GumballMachineState.NoQuarter) { Console.WriteLine("You haven't inserted a quarter"); } else if (_state == GumballMachineState.Sold) { Console.WriteLine("Sorry, you already turned the crank"); } else if (_state == GumballMachineState.SoldOut) { Console.WriteLine("You can't eject, you haven't inserted a quarter yet"); } }
public void InsertQuarter() { if (_state == GumballMachineState.HasQuarter) { Console.WriteLine("You can't insert another quarter"); } else if (_state == GumballMachineState.NoQuarter) { _state = GumballMachineState.HasQuarter; Console.WriteLine("You inserted a quarter"); } else if (_state == GumballMachineState.SoldOut) { Console.WriteLine("You can't insert a quarter, the machine is sold out"); } else if (_state == GumballMachineState.Sold) { Console.WriteLine("Please wait, we're already giving you a gumball"); } }
public void InsertQuarter() { if (_state == GumballMachineState.HasQuarter) { _log.Append("You can't insert another quarter\n"); } else if (_state == GumballMachineState.NoQuarter) { _state = GumballMachineState.HasQuarter; _log.Append("You inserted a quarter\n"); } else if (_state == GumballMachineState.SoldOut) { _log.Append("You can't insert a quarter, the machine is sold out\n"); } else if (_state == GumballMachineState.Sold) { _log.Append("Please wait, we're already giving you a gumball\n"); } }
public void EjectQuarter() { if (_state == GumballMachineState.HasQuarter) { _log.Append("Quarter returned\n"); _state = GumballMachineState.NoQuarter; } else if (_state == GumballMachineState.NoQuarter) { _log.Append("You haven't inserted a quarter\n"); } else if (_state == GumballMachineState.Sold) { _log.Append("Sorry, you already turned the crank\n"); } else if (_state == GumballMachineState.SoldOut) { _log.Append("You can't eject, you haven't inserted a quarter yet\n"); } }
public void TurnCrank() { if (_state == GumballMachineState.Sold) { Console.WriteLine("Turning twice doesn't get you another gumball!"); } else if (_state == GumballMachineState.NoQuarter) { Console.WriteLine("You turned but there's no quarter"); } else if (_state == GumballMachineState.SoldOut) { Console.WriteLine("You turned, but there are no gumballs"); } else if (_state == GumballMachineState.HasQuarter) { Console.WriteLine("You turned..."); _state = GumballMachineState.Sold; Dispense(); } }
public void TurnCrank() { if (_state == GumballMachineState.Sold) { _log.Append("Turning twice doesn't get you another gumball!\n"); } else if (_state == GumballMachineState.NoQuarter) { _log.Append("You turned but there's no quarter\n"); } else if (_state == GumballMachineState.SoldOut) { _log.Append("You turned, but there are no gumballs\n"); } else if (_state == GumballMachineState.HasQuarter) { _log.Append("You turned...\n"); _state = GumballMachineState.Sold; Dispense(); } }
public void InsertQuarter() { switch (_state) { case GumballMachineState.HasQuarter: Console.WriteLine("You can't insert another quarter"); break; case GumballMachineState.NoQuarter: _state = GumballMachineState.HasQuarter; Console.WriteLine("You inserted a quarter"); break; case GumballMachineState.Sold: Console.WriteLine("Please wait... gumball is coming..."); break; case GumballMachineState.SoldOut: Console.WriteLine("You can't insert a quarter, the machine is sold out"); break; } }
public void EjectQuarter() { switch (_state) { case GumballMachineState.HasQuarter: _state = GumballMachineState.NoQuarter; Console.WriteLine("Quarter returned"); break; case GumballMachineState.NoQuarter: Console.WriteLine("You haven't inserted a quarter"); break; case GumballMachineState.Sold: Console.WriteLine("You already turned the crank"); break; case GumballMachineState.SoldOut: Console.WriteLine("You haven't inserted a quarter"); break; } }
public void TurnCrank() { switch (_state) { case GumballMachineState.HasQuarter: Console.WriteLine("You turned..."); _state = GumballMachineState.Sold; Dispense(); break; case GumballMachineState.NoQuarter: Console.WriteLine("You turned, but no quarter"); break; case GumballMachineState.Sold: Console.WriteLine("Turning twice doesn't get you another gumball..."); break; case GumballMachineState.SoldOut: Console.WriteLine("You turned, but there are no gumballs..."); break; } }
public void Refill(int numGumBalls) { _count = numGumBalls; _state = GumballMachineState.NoQuarter; }