Skip to main content

Bottle recycling machine state diagram

Short answer

Control unit states: Waiting (initial), On Run (composite with Working, Blocked, Failure Notification, Emptying sub-states), Receipt Printing, On Service. Transitions: bottleDetected starts On Run; jam moves to Blocked; timeout triggers Failure Notification; endPressed with sum>0 goes to Receipt Printing; serviceKey enters On Service; serviceFinished returns to Waiting.

Bottle recycling machine has a control unit, bottle sensor, belt-unit, the sum counter, the end button and the receipt printer. There are at least states such as waiting, on run, on service and receipt printing. The "on run" state can be refined with sub-states working, blocked, failure notification, emptying. You can add few new states according to your own realization. Draw a state diagram for the control unit.

Assumptions (extra states and events): Waiting is the initial state; entering Receipt Printing totals the deposit before printing; a Failure Notification leads to On Service. Events: bottleDetected, endPressed, jam, serviceKey, receiptPrinted, serviceFinished.

State diagram of the control unit

 (*)
  |
  v
 +--------------+   bottle detected    +------------------+
 |   Waiting    |--------------------->|      On Run      |
 | do/ monitor  |<---------------------|   (composite)    |
 |   sensor     |  timeout [sum = 0]   +------------------+
 +--------------+                        |             |
   ^  |     ^               end button   |             | from Failure
   |  |     |               [sum > 0]    |             | Notification /
   |  |     |                            v             v call service
   |  |     |              +------------------+  +--------------+
   |  |     +--------------| Receipt Printing |  |  On Service  |
   |  |   receipt printed  | entry/ total sum |  | do/ repair,  |
   |  |   / sum = 0        | do/ print        |  |  maintenance |
   |  |                    +------------------+  +--------------+
   |  |        service key                          |   ^
   |  +---------------------------------------------|---+
   +--------------- service finished ---------------+

Sub-states of "On Run"

 +-----------------------------------------------------------+
 | On Run                                                    |
 |                                                           |
 |  (*)                                                      |
 |   |    bottle accepted / sum += value (self-transition)   |
 |   v                                                       |
 | +---------+     storage full      +----------+            |
 | | Working |---------------------->| Emptying |            |
 | |         |<----- emptied --------|          |            |
 | +---------+                       +----------+            |
 |   |     ^                                                 |
 |   | jam | cleared /                                       |
 |   | /   | restart belt                                    |
 |   | stop|                                                 |
 |   v belt|                                                 |
 | +---------+     timeout           +----------------------+|
 | | Blocked |---------------------->| Failure Notification ||
 | +---------+                       | entry/ raise alarm   ||
 |                                   +----------------------+|
 +-----------------------------------------------------------+

Transition table

FromEvent [guard] / actionTo
Waitingbottle detectedOn Run (Working)
Workingbottle accepted / sum += valueWorking
Workingjam detected / stop beltBlocked
Blockedcleared / restart beltWorking
Blockedtimeout > limitFailure Notification
Workingstorage fullEmptying
EmptyingemptiedWorking
On Runtimeout [sum = 0]Waiting
On Runend button [sum > 0]Receipt Printing
Receipt Printingreceipt printed / sum = 0Waiting
Waitingservice keyOn Service
Failure Notificationcall serviceOn Service
On Serviceservice finishedWaiting

Entry/exit actions: entering Receipt Printing computes the total; leaving it resets the counter.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Object Oriented Analysis and Design chapter 2 questions →