示例#1
0
 public void dispense()
 {
     gumballMachine.releaseBall();
     if (gumballMachine.getCount() == 0)
     {
         gumballMachine.setState(gumballMachine.getSoldOutState());
     }
     else
     {
         gumballMachine.releaseBall();
         Console.WriteLine("YOU'RE A WINNER! You got two gumballs for your quarter");
         if (gumballMachine.getCount() > 0)
         {
             gumballMachine.setState(gumballMachine.getNoQuarterState());
         }
         else
         {
             Console.WriteLine("Oops, out of gumballs!");
             gumballMachine.setState(gumballMachine.getSoldOutState());
         }
     }
 }
示例#2
0
 public void dispense()
 {
     gumballMachine.releaseBall();
     if (gumballMachine.getCount() > 0)
     {
         gumballMachine.setState(gumballMachine.getNoQuarterState());
     }
     else
     {
         Console.WriteLine("Oops, out of gumballs!");
         gumballMachine.setState(gumballMachine.getSoldOutState());
     }
 }