The Depositing state keeps track of how much money has been deposited
into the vending machine.
In this step, you will do the following:
- create the Depositing state
- add an entry and an exit for the Depositing state
- Create a self-transition on the Depositing state
- add an operation, a condition and an action to this self-transition
- From the palette, click the state icon,
drop it onto the canvas well to the right of the Idle state, and rename it Depositing.
- Create an entry on the Deposit state named enterDepositing with
the following code:
System.out.println("Entering the Depositing state");
- Similarly, create an exit on the Deposit state named leavingDepositing with
the following code:
System.out.println("Leaving the Depositing state");
- Create and configure a self transition on the Deposit state. A self transition is one in which the source state and the target state
are the same. In this case, the transition going out of the Depositing state
is executed with each subsequent coin that is deposited. It checks the validity
of the coin, adds the value of the coin to the running total, and then returns
to the Depositing state where the state machine will then wait for the next
event to occur.
- Hover over the Deposit state until a yellow grabber appears
as shown in this image.

- Left-click your mouse to create the beginning of the transition,
and then drag the cursor back over the Deposit state and click it. A self
transition will appear as shown in this image:

- Drag the deposit operation onto this
transition.
- Add a condition named isCoinValid to
this transition with the following code:
System.out.println("Money is being deposited in VendingMachine. Checking to see if the coin is valid");
double coin = deposit_Input_coin.getDouble("value");
if (coin == 1.0d || coin == 2.0d || coin == 0.25d || coin == 0.1d || coin == 0.05d)
return true;
return false;
- Add an action named updateTotal to this
transition with the following code:
double coin = deposit_Input_coin.getDouble("value");
double newTotal = total.doubleValue() + coin;
total = new Double(newTotal);
System.out.println("Successfully deposited "+coin+" in the VendingMachine");
Your Depositing state and its self-transitions should look like this
image:
