public override void Dispense()
 {
     Console.WriteLine("YOU'RE A WINNER! You get two gumballs for your quarter");
     try
     {
         gumballMachine.ReleaseBall();
         if (gumballMachine.GetCount() == 0)
         {
             gumballMachine.SetState(gumballMachine.GetSoldOutState());
         }
         else
         {
             gumballMachine.ReleaseBall();
             if (gumballMachine.GetCount() > 0)
             {
                 gumballMachine.SetState(gumballMachine.GetNoQuarterState());
             }
             else
             {
                 Console.WriteLine("Oops, out of gumballs!");
                 gumballMachine.SetState(gumballMachine.GetSoldOutState());
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#2
0
 public override void Dispense()
 {
     gumballMachine.ReleaseBall();
     try
     {
         if (gumballMachine.GetCount() > 0)
         {
             gumballMachine.SetState(gumballMachine.GetNoQuarterState());
         }
         else
         {
             Console.WriteLine("Oops, out of gumballs!");
             gumballMachine.SetState(gumballMachine.GetSoldOutState());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }