$30
Unit 12 Assignment
Write an OO (C++, Java, Python, Objective C, Ada, C#) program to implement the Finite
State Automaton depicted below. You must use the State design pattern. The program
must have classes for the client, context, abstract state and concrete states (4 concrete
states). The classes are:
Client – main entry point that contains a single instance of the context class
Context – delegates responsibility for handling input to the single currently active
concrete state
Abstract State – defines the two abstract or pure virtual operations (OnA, OnB)
Concrete State(s) – implement the three operations and update the Context when
switching from one concrete state to another. For example, in the picture below
while in state 2 if a a “b” is input in main, main calls the context OnB operation
(which is not derived from Abstract State), and the Context. OnB() operation calls
current. OnB() which in this case is a ConcreteState2 object. Its OnB() operation
prints the “b”, creates a new ConcreteState4 object and alerts context to change it
single currently active concrete state instance (confusingly stored in an
AbstractState variable) to be set to the new class.
Submit all the code in one text, word or pdf file.
States are:
1 2
3 4
Text input and output are acceptable.