2
votes

i am trying to develop an UML state machine diagram for the following problem:

a vending machine has 3 buttons: R for 'return money, A & B for drink selections. when the vending machine receives amount x of money the user can choose between the drinks. pressing R returns the money without serving a drink.

if a button is pressed before any money is inserted - the machine produces an alarm signal. in case A or B is pressed and >= x money is inserted - the drink will be served.

when serving is done, an alarm sound notifies the user. the change money gets returned. after taking out the drink, the machine goes into the end-state.

enter image description here

my issue is that i am working with parallel 'processes' and i believe that there must be a simple configuration for this scenario. can somebody provide/guide me with the right ideas to solve this in an elegant way?

edit: after using the suggestion of @Chris Reynolds i came up with this:

state machine

2
In a state machine, I believe the bubbles should only be states and your example feels very process oriented. I would just have three states: Inactive, Payment-in-Progress,Ready-to-Serve. Then for each state, you have to handle 4 events: Buttons A,B,R and Coin-Received.Chris Reynolds
A point, what's should happen after "if a button is pressed before any money is inserted - the machine produces an alarm signal" because you stay in this state, i guess some event should stop the alarm no ?granier
another point, on your schema, are there event ? It seems that most of your transistions are guarded without event except for the two lastgranier
and last, what could be parallel in your state machine ? The user does action one by one no ?granier
granier: yes i forgot to implement the association btw alarm-signal and end. also i have to admit that i completely misunderstood the whole idea behind. i used Chris Reynolds suggestion and came but with what is now attached in my edit. is that the way to do it?tingtong

2 Answers

2
votes

So the state machine is profoundly different if all products are the same price. It can be captured in this table: enter image description here

2
votes

Actually there is no parallel process in this state machine*:

enter image description here

The state Return money is reached by pressing the R button during Collect money and while waiting for A and B. It sounds an alarm if money is present. You might add behavior to the transition from Collect money if there's no credit for a different alarm, or just a new transition to self.

*: Assuming that further coin acceptance is blocked once enough money is inserted.