Beispiel #1
0
 public void dispense() {
   System.out.println("YOU'RE A WINNER! You get two gumballs for your quarter");
   gumballMachine.releaseBall();
   if (gumballMachine.getCount() == 0) {
     gumballMachine.setState(gumballMachine.getSoldOutState());
   } else {
     gumballMachine.releaseBall();
     if (gumballMachine.getCount() > 0) {
       gumballMachine.setState(gumballMachine.getNoQuarterState());
     } else {
       System.out.println("Oops, out of gumballs!");
       gumballMachine.setState(gumballMachine.getSoldOutState());
     }
   }
 }
Beispiel #2
0
 public void dispense() {
   gumballMachine.releaseBall();
   if (gumballMachine.getCount() > 0) {
     gumballMachine.setState(gumballMachine.getNoQuarterState());
   } else {
     System.out.println("Oops, out of gumballs!");
     gumballMachine.setState(gumballMachine.getSoldOutState());
   }
 }
Beispiel #3
0
 public void dispense() {
   gumballMachine.releaseBall();
   if (gumballMachine.getCount() > 0) {
     gumballMachine.setState(gumballMachine.getNoQuarterState());
   } else {
     System.out.println("PANIC WE SOLD ALL BALLS!");
     gumballMachine.setState(gumballMachine.getSoldOutState());
   }
 }
 @Override
 public void tumCrank() {
   System.out.println("You turned...");
   int winner = rnd.nextInt(10);
   if (winner == 0 && gumballMachine.getCount() > 1) {
     gumballMachine.setState(gumballMachine.getWinnerState());
   } else {
     gumballMachine.setState(gumballMachine.getSoldState());
   }
 }
 public void dispense() {
   gumballMachine.releaseBall();
   try {
     if (gumballMachine.getCount() > 0) {
       gumballMachine.setState(gumballMachine.getNoQuarterState());
     } else {
       System.out.println("Oops, out of gumballs!");
       gumballMachine.setState(gumballMachine.getSoldOutState());
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public boolean isGumballInSlot() {
   if (gumballMachine.getCount() >= 2) return true;
   else return false;
 }