コード例 #1
0
 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;
     }
 }
コード例 #3
0
 public void Report()
 {
     Console.WriteLine("Gumball Machine: " + machine.GetLocation());
     Console.WriteLine("Current inventory: " + machine.GetCount() + " gumballs");
     Console.WriteLine("Current state: " + machine.GetState());
 }