Exemple #1
0
 public VendingMachine(int numberOfItems)
 {
     this.NumberOfItems = numberOfItems;
     this.SoldOutState  = new SoldOutState(this);
     this.NoMoneyState  = new NoMoneyState(this);
     this.HasMoneyState = new HasMoneyState(this);
     this.SoldState     = new SoldState(this);
     if (numberOfItems > 0)
     {
         this.CurrentState = this.NoMoneyState;
     }
 }
Exemple #2
0
 public void DispenseProduct()
 {
     vendingMachineState.DispenseProduct();
     // Product has been dispensed so vending Machine changed the
     // internal state to 'NoMoneyState'
     if (vendingMachineState is HasMoneyState)
     {
         vendingMachineState = new NoMoneyState();
         Console.WriteLine("VendingMachine internal state has been moved to : "
                           + vendingMachineState.GetType().Name);
     }
 }
Exemple #3
0
 public void SelectProductAndInsertMoney(int amount, string productName)
 {
     vendingMachineState.SelectProductAndInsertMoney(amount, productName);
     // Money has been inserted so vending Machine internal state
     // changed to 'hasMoneyState'
     if (vendingMachineState is NoMoneyState)
     {
         vendingMachineState = new HasMoneyState();
         Console.WriteLine("VendingMachine internal state has been moved to : "
                           + vendingMachineState.GetType().Name);
     }
 }
 /// <summary>
 /// Vending machine that dispenses cans
 /// </summary>
 public SimpleVendingMachine()
 {
     State = new ItemSelectedState(this);
 }
 public void SetState(IVendingMachineState state)
 {
     CurrentState = state;
 }
Exemple #6
0
 //Initially the vending machine has NoMoneyState
 public VendingMachine()
 {
     vendingMachineState = new NoMoneyState();
 }