// Test case 5 : Inserting more then 50 cents and checking for change and Gumball in slot
 @Test
 public void testFiftyPlusSecond() {
   gumballM1.insertDime();
   gumballM1.insertDime();
   gumballM1.insertDime();
   gumballM1.insertQuarter();
   gumballM1.turnCrank();
   assertEquals(true, gumballM1.isGumballInSlot());
 }
예제 #2
0
 public void turnCrank() {
   System.out.println("You turned...");
   int winner = randomWinner.nextInt(10);
   if (winner == 0) {
     gumballMachine.setState(gumballMachine.getWinnerState());
   } else {
     gumballMachine.setState(gumballMachine.getSoldState());
   }
 }
예제 #3
0
 @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());
   }
 }
예제 #4
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());
     }
   }
 }
 // Test case 6 : Insert 2 quarters and turn crank and Insert 2 quarters again and turn crank
 // Chenking to see if multiple time inserting 50 cents dispences the gumball
 @Test
 public void testCountOfGumballsInSlot() {
   gumballM1.insertQuarter();
   gumballM1.insertQuarter();
   gumballM1.turnCrank();
   gumballM1.insertQuarter();
   gumballM1.insertQuarter();
   gumballM1.turnCrank();
   assertEquals(true, gumballM1.isGumballInSlot());
   gumballM1.takeGumballFromSlot();
   assertEquals(false, gumballM1.isGumballInSlot());
 }
 // Test case 8 : Testing eject method and get cents back method
 @Test
 public void testEjectAndCentsBackCheck() {
   gumballM1.insertQuarter();
   gumballM1.ejectNickel();
   gumballM1.insertDime();
   gumballM1.insertDime();
   gumballM1.insertQuarter();
   // assertEquals(15, gumballM1.getChange());
   assertEquals(false, gumballM1.isGumballInSlot());
   gumballM1.turnCrank();
   assertEquals(true, gumballM1.isGumballInSlot());
 }
 // Test case 4 :Try to take a dispensed gumball and crank the machine again without inserting any
 // coin
 @Test
 public void testTakeGumballAndCrankAgainWithoutInsertingAnyCoinQDNNN() {
   gumballM1.insertQuarter();
   gumballM1.insertDime();
   gumballM1.insertNickel();
   gumballM1.insertNickel();
   gumballM1.insertNickel();
   gumballM1.turnCrank();
   gumballM1.takeGumballFromSlot();
   soldState.turnCrank();
   assertEquals(false, gumballM1.isGumballInSlot());
 }
예제 #8
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());
   }
 }
예제 #9
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());
   }
 }
 // Test case 1: insert 1 quarter, insert 1 dime and 3 nickel = 50Cents : +ve test case
 @Test
 public void testQDNNNHappy() {
   gumballM1.insertQuarter();
   gumballM1.insertDime();
   gumballM1.insertNickel();
   gumballM1.insertNickel();
   gumballM1.insertNickel();
   gumballM1.turnCrank();
   assertEquals(true, gumballM1.isGumballInSlot());
 }
 // Test Case 9: Insert 50 cents first but remove some amount before
 // turning crank then check to see if gumball is dispenced or not : -ve test case
 @Test
 public void TestQDDDDEjectQNegative() {
   gumballM1.insertQuarter();
   gumballM1.insertDime();
   gumballM1.insertDime();
   gumballM1.insertDime();
   gumballM1.ejectQuarter();
   gumballM1.turnCrank();
   assertEquals(false, gumballM1.isGumballInSlot());
 }
 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();
   }
 }
 // Test case 10 : Checking whether the machine slot already has a gumball in the beginning
 @Test
 public void testGumballInSlotInTheBeginning() {
   assertEquals(false, gumballM1.isGumballInSlot());
 }
예제 #14
0
 @Override
 public void insertQuarter() {
   System.out.println("投币完成");
   gumballMachine.setState(gumballMachine.getHasQuarterStatus());
 }
 // Test Case 7 : Negative test case : No gumball should return when less then 50 cents inserted
 // and turned crank
 @Test
 public void testAddOneQuarterNeg() {
   gumballM1.insertQuarter();
   gumballM1.turnCrank();
   assertEquals(false, gumballM1.isGumballInSlot());
 }
예제 #16
0
 @Override
 public void turnCrank() {
   System.out.println("You turned crank!");
   machine.setState(machine.getSoldState());
   machine.dispense();
 }
  /** @param args the command line arguments */
  public static void main(String[] args) {

    System.out.println("GumBalls State Pattern Application");
    System.out.println("----------------------------------");

    GumballMachine gm = new GumballMachine(5);

    System.out.println("");
    gm.insertQuarter();
    System.out.println("\t\tafter inserting a quarter" + gm);
    gm.turnCrankFetchGumball();
    System.out.println("\t\tafter turncrank to fetchgumball" + gm);

    System.out.println("");
    gm.insertQuarter();
    System.out.println("\t\tafter inserting a quarter" + gm);
    gm.ejectQuarter();
    System.out.println("\t\twe ejected the quarter" + gm);
    gm.turnCrankFetchGumball();
    System.out.println("\t\tafter turncrank to fetchgumball" + gm);

    System.out.println("");
    gm.insertQuarter();
    System.out.println("\t\tafter inserting a quarter" + gm);
    gm.turnCrankFetchGumball();
    System.out.println("\t\tafter turncrank to fetchgumball" + gm);
    gm.insertQuarter();
    System.out.println("\t\tafter inserting a quarter" + gm);
    gm.turnCrankFetchGumball();
    System.out.println("\t\tafter turncrank to fetchgumball" + gm);
    gm.ejectQuarter();
    System.out.println("\t\twe ejected the quarter" + gm);

    System.out.println("");
    gm.insertQuarter();
    System.out.println("\t\tafter inserting a quarter" + gm);
    gm.insertQuarter();
    System.out.println("\t\tafter inserting a quarter" + gm);
    gm.turnCrankFetchGumball();
    System.out.println("\t\tafter turncrank to fetchgumball" + gm);
    gm.insertQuarter();
    System.out.println("\t\tafter inserting a quarter" + gm);
    gm.turnCrankFetchGumball();
    System.out.println("\t\tafter turncrank to fetchgumball" + gm);
    gm.insertQuarter();
    System.out.println("\t\tafter inserting a quarter" + gm);
    gm.turnCrankFetchGumball();
    System.out.println("\t\tafter turncrank to fetchgumball" + gm);

    System.out.println("");
    gm.insertQuarter();
    System.out.println("\t\tafter inserting a quarter" + gm);
    gm.turnCrankFetchGumball();
    System.out.println("\t\tafter turncrank to fetchgumball" + gm);

    System.out.println("");
    System.out.println("----------------------------------");
  }
예제 #18
0
 public void insertQuarter() {
   gm.setState(gm.getHasQuarterState()); // state = HAS_QUARTER;
   System.out.println("You inserted a quarter");
 }
예제 #19
0
 @Override
 public void ejectQuarter() {
   System.out.println("Quarter ejected");
   this.machine.setState(machine.getNoQuarterState());
 }
예제 #20
0
 public void insertQuarter() {
   System.out.println("insertQ: You inserted a quarter");
   gm.setState(gm.getHasQuarterState());
 }
예제 #21
0
 public void ejectQuarter() {
   System.out.println("Refund of " + fund + " is being returned to you.");
   fund = 0;
   gumballMachine.setState(gumballMachine.getInsufficientFundState());
 }
 public void refill() {
   gumballMachine.setState(gumballMachine.getNoQuarterState());
 }
  public static void main(String[] args) {
    GumballMachine gumballMachine = new GumballMachine(10);

    System.out.println(gumballMachine);

    gumballMachine.insertQuarter();
    gumballMachine.turnCrank();
    gumballMachine.insertQuarter();
    gumballMachine.turnCrank();

    System.out.println(gumballMachine);

    gumballMachine.insertQuarter();
    gumballMachine.turnCrank();
    gumballMachine.insertQuarter();
    gumballMachine.turnCrank();

    System.out.println(gumballMachine);

    gumballMachine.insertQuarter();
    gumballMachine.turnCrank();
    gumballMachine.insertQuarter();
    gumballMachine.turnCrank();

    System.out.println(gumballMachine);

    gumballMachine.insertQuarter();
    gumballMachine.turnCrank();
    gumballMachine.insertQuarter();
    gumballMachine.turnCrank();

    System.out.println(gumballMachine);

    gumballMachine.insertQuarter();
    gumballMachine.turnCrank();
    gumballMachine.insertQuarter();
    gumballMachine.turnCrank();

    System.out.println(gumballMachine);
  }
 // Test case 3 : Checking whether gumball will be dispensed before inserting any coin
 @Test
 public void testCrankWithoutInsertingAnyCoin() {
   gumballM1.turnCrank();
   assertEquals(false, gumballM1.isGumballInSlot());
 }
예제 #25
0
 public boolean isGumballInSlot() {
   if (gumballMachine.getCount() >= 2) return true;
   else return false;
 }
예제 #26
0
 @Override
 public void ejectQuarter() {
   System.out.println("Quarter returned");
   gumballMachine.setState(gumballMachine.getNoQuarterState());
 }
예제 #27
0
 public void turnCrank() {
   System.out.println("You turned...");
   gumballMachine.setState(gumballMachine.getSoldState());
 }
 public void insertQuarter() {
   System.out.println("You inserted a quarter");
   gumballMachine.setState(gumballMachine.getHasQuarterState());
 }