Constructing a FSM for a ticket machine

30 views Asked by At

Design a FSM for a train ticket machine.

Destination FSM: M. The user selects the destination by entering either A, B or C. When the user selects B the user has the option to select N for no connecting trains; D for a connecting train from B to D; or E for a connecting train from B to E.

Ticket Type, Pay and Dispense FSM: P. The user selects the ticket type, O for one-way ticket and R for a return ticket. The user then pays for the ticket by contactless card. If the payment is approved P will dispense the ticket otherwise no ticket will be dispensed.

The Train Ticket FSM: X.Combine the destination FSM M and the ticket type, pay and dispense FSM P to build a FSM X for the train ticket machine.

Can someone help me how to do this? I am new to FSM, and I don't have an idea how to design this. I found this question online, and thought it is a good question for practice.

I did start identifying the states and which inputs will take me to the next state. But the thing is we have to consider all the inputs at each state. So, when we consider the first part, when the user selects A he will be taken to an acceptance state. In that state, what will be the next state for the inputs A, B, C, D, E, and N? I'm confused. If someone can help me with this, I really appreciate it.

1

There are 1 answers

0
paulscreationids On

State A leads to the acceptance state. From there, inputs B, C, and D transition to their respective sub-states for further options, while N and E prompt a return to the initial state for reselection. State B diverges into sub-states D, E, and N based on user input, each leading to further options or the initial state. Successful payment in any state leads to ticket dispensing, while failed payment returns to the initial state.