コード例 #1
0
        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;
            }
        }
コード例 #2
0
 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");
     }
 }
コード例 #3
0
 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");
     }
 }
コード例 #4
0
ファイル: GumballMachine.cs プロジェクト: ronymaychan/demos
 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");
     }
 }
コード例 #5
0
 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");
     }
 }
コード例 #6
0
 public void StartWithQuarters(int count)
 {
     this._count = count;
     if (_count > 0)
     {
         _state = GumballMachineState.NoQuarter;
     }
 }
コード例 #7
0
 public GumballMachine(int count)
 {
     this._count = count;
     if (_count > 0)
     {
         _state = GumballMachineState.NoQuarter;
     }
 }
コード例 #8
0
 public GumballMachine(int totalBalls)
 {
     _totalBalls = totalBalls;
     if (_totalBalls > 0)
     {
         _state = GumballMachineState.NoQuarter;
     }
 }
コード例 #9
0
 public GumballMachine(int count)
 {
     this._count = count;
     if (_count > 0)
     {
         _state = GumballMachineState.NoQuarter;
     }
 }
コード例 #10
0
 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");
     }
 }
コード例 #11
0
 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");
     }
 }
コード例 #12
0
 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");
     }
 }
コード例 #13
0
 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");
     }
 }
コード例 #14
0
 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");
     }
 }
コード例 #15
0
 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();
     }
 }
コード例 #16
0
 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();
     }
 }
コード例 #17
0
        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;
            }
        }
コード例 #18
0
        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;
            }
        }
コード例 #19
0
        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;
            }
        }
コード例 #20
0
ファイル: GumballMachine.cs プロジェクト: ronymaychan/demos
 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");
     }
 }
コード例 #21
0
ファイル: GumballMachine.cs プロジェクト: ronymaychan/demos
 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();
     }
 }
コード例 #22
0
ファイル: GumballMachine.cs プロジェクト: ronymaychan/demos
 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");
     }
 }
コード例 #23
0
 public void Refill(int numGumBalls)
 {
     _count = numGumBalls;
     _state = GumballMachineState.NoQuarter;
 }
コード例 #24
0
 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();
     }
 }
コード例 #25
0
 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");
     }
 }
コード例 #26
0
ファイル: GumballMachine.cs プロジェクト: ronymaychan/demos
 public void StartWithQuarters(int count)
 {
     this._count = count;
     if (_count > 0)
     {
         _state = GumballMachineState.NoQuarter;
     }
 }
コード例 #27
0
 public void Refill(int numGumBalls)
 {
     _count = numGumBalls;
     _state = GumballMachineState.NoQuarter;
 }