Search code examples
umlstate-machine

Struggling in drawing State machine diagram


Hey there I'm trying to draw state machine diagram for this scenario but It's missing lots of information. If someone here could help out with it.

The Scenario

  1. Tourists will start the journey by selecting the trip using the Automated Ticketing system (ATS).
  2. The Automated Ticketing System (ATS) will display the trip details.
  3. This Trip details will include the seat-number and destination.
  4. Based on provided trip details, the ATS will compute payment.
  5. The tourist has the option to pay the payment by cash or credit card.
  6. If the tourist will insert a wrong amount of cash, the ATS will display "Insert More Cash" message on the screen until the correct amount will be inserted.
  7. If payment by card was selected by the tourist, the ATS will perform two parallel tasks. It will validate the expiration date of the card and check the credit balance. If card is accepted, the bank will authorize the payment and will update the account of the tourist. However, if card is not accepted or invalid, the ATS will again ask for payment option (back to step 5) from the tourist.
  8. After payment is complete, the ticket and receipt are printed by the ATS.
  9. Cash payment might result in some change, so the change is also dispensed by the ATS. The tourist will then get the ticket and the change.
  10. ATS will display the message "Transaction Complete" at the end of the transaction.

My Drawing:

enter image description here


Solution

  • Ok, so I try to give you some hints. A state machine is always created for a single class, not the overall system under consideration. So let's assume the ATS is a single class (in reality it will probably be more a component consisting of several classes). Now this ATS will in the beginning be idle. It is triggered somehow when a trip is selected. It then has to complete the journey details. It waits for payment and finally it will spit out a ticket. Now (basically!) the state machine looks like this:

    enter image description here

    This is a scaffold and it was done without reading the details above. Note that instead of the cancel transitions you could use a general exception from an interruptible region which eventually clears payments. In practice you would likely do that since a cancellation should (from a user perspective) be possible at any point. A time out of course would also be possible (what if already some cash had been paid?).

    Also I did not include the do/entry/exit actions. For the cash this would be something like add new cash sum so we know when enough money has been paid.