ATM Simulation Example: AG Software Engineering: Processes and Measurement
ATM Simulation Example: AG Software Engineering: Processes and Measurement
TABBLE OF CONTENTS
I. REQUIREMENT SPECIFICATION........................................................................................................................... 2
6. CLASS DESCRIPTIONS.............................................................................................................................................27
7. STRUCTURAL VIEW: CLASS DIAGRAM FOR EXAMPLE ATM SYSTEM .........................................................................29
8. STATE CHARTS FOR EXAMPLE ATM SYSTEM ..........................................................................................................31
I. Requirement Specification
The ATM will service one customer at a time. A customer will be required to insert an ATM card
and enter a personal identification number (PIN) - both of which will be sent to the bank for
validation as part of each transaction. The customer will then be able to perform one or more
transactions. The card will be retained in the machine until the customer indicates that he/she
desires no further transactions, at which point it will be returned - except as noted below.
The ATM must be able to provide the following services to the customer:
1. A customer must be able to make a cash withdrawal from any suitable account linked to
the card, in multiples of $20.00. Approval must be obtained from the bank before cash
is dispensed.
2. A customer must be able to make a deposit to any account linked to the card, consisting
of cash and/or checks in an envelope. The customer will enter the amount of the
deposit into the ATM, subject to manual verification when the envelope is removed
from the machine by an operator. Approval must be obtained from the bank before
physically accepting the envelope.
3. A customer must be able to make a transfer of money between any two accounts linked
to the card.
4. A customer must be able to make a balance inquiry of any account linked to the card.
A customer must be able to abort a transaction in progress by pressing the Cancel key instead of
responding to a request from the machine.
The ATM will communicate each transaction to the bank and obtain verification that it was
allowed by the bank. Ordinarily, a transaction will be considered complete by the bank once it
has been approved. In the case of a deposit, a second message will be sent to the bank
indicating that the customer has deposited the envelope. (If the customer fails to deposit the
envelope within the timeout period, or presses cancel instead, no second message will be sent
to the bank and the deposit will not be credited to the customer.)
If the bank determines that the customer's PIN is invalid, the customer will be required to re -
enter the PIN before a transaction can proceed. If the customer is unable to successfully enter
the PIN after three tries, the card will be permanently retained by the machine, and the
customer will have to contact the bank to get it back.
If a transaction fails for any reason other than an invalid PIN, the ATM will display an explanation
of the problem, and will then ask the customer whether he/she wants to do another
transaction.
The ATM will provide the customer with a printed receipt for each successful transaction,
showing the date, time, machine location, type of transaction, account(s), amount, and ending
and available balance(s) of the affected account ("to" account for transfers).
The ATM will have a key-operated switch that will allow an operator to start and stop the
servicing of customers. After turning the switch to the "on" position, the operator will be
required to verify and enter the total cash on hand. The machine can only be turned off when it
is not servicing a customer. When the switch is moved to the "off" position, the machine will
shut down, so that the operator may remove deposit envelopes and reload the machine with
cash, blank receipts, etc.
The ATM will also maintain an internal log of transactions to facilitate resolving ambiguities
arising from a hardware failure in the middle of a transaction. Entries will be made in the log
when the ATM is started up and shut down, for each message sent to the Bank (along with the
response back, if one is expected), for the dispensing of cash, and for the receiving of an
envelope. Log entries may contain card numbers and dollar amounts, but for security
will never contain a PIN.
The customer may abort the session by pressing the Cancel key when entering a PIN or
choosing a transaction type.
A transaction use case is started within a session when the customer chooses a
transaction type from a menu of options. The customer will be asked to furnish
appropriate details (e.g. account(s) involved, amount). The transaction will then be sent
to the bank, along with information from the customer's card and the PIN the customer
entered.
If the bank approves the transaction, any steps needed to complete the transaction (e.g.
dispensing cash or accepting an envelope) will be performed, and then a receipt will be
printed. Then the customer will be asked whether he/she wishes to do another
transaction.
If the bank reports that the customer's PIN is invalid, the Invalid PIN extension will be
performed and then an attempt will be made to continue the transaction. If the
customer's card is retained due to too many invalid PINs, the transaction will be
aborted, and the customer will not be offered the option of doing another.
If a transaction is cancelled by the customer, or fails for any reason other than repeated
entries of an invalid PIN, a screen will be displayed informing the customer of the reason
for the failure of the transaction, and then the customer will be offered the opportunity
to do another.
The customer may cancel a transaction by pressing the Cancel key as described for each
individual type of transaction below.
All messages to the bank and responses back are recorded in the ATM's log.
A withdrawal transaction can be cancelled by the customer pressing the Cancel key any
time prior to choosing the dollar amount.
A deposit transaction can be cancelled by the customer pressing the Cancel key any time
prior to inserting the envelope containing the deposit. The transaction is automatically
cancelled if the customer fails to insert the envelope containing the deposit within a
reasonable period of time after being asked to do so.
A transfer transaction can be cancelled by the customer pressing the Cancel key any
time prior to entering a dollar amount.
An inquiry transaction can be cancelled by the customer pressing the Cancel key any
time prior to choosing the account to inquire about.
If the customer presses Cancel instead of re-entering a PIN, the original transaction is
cancelled.
a. Abstraction level
The transactions are considered at the general level, i.e. only the Transaction Use Case is
considered and not detailed ones like Inquiry Transaction Use Case or Deposit Transaction Use
Case. All other use cases are considered.
The transaction information are always correct, i.e. the only reason for a transaction not
working is an incorrect PIN.
b. Requirement Tags
Tags Requirements
1 System Startup Use Case
2 System Shutdown Use Case
3 Session Use Case
4 Transaction Use Case
5 Invalid PIN Extension
c. Stimuli
d. Responses
e. Enumeration of sequences
Only sequences of length 0, 1, 2 and 3 are enumerated. You will be asked in an exercise class to
continue the enumeration.
D2 After the switch is turned on, its physically impossible to turn it on again
D3 After the switch is turned on, the only valid Stimuli is INIT and SOFF
Some writers would argue for developing test cases like these in place of use cases.
Here, they are presented as a vehicle for "fleshing out" the use cases, not as a substitute
for them.
System is started
System Activate the "on" System requests
when the switch is System is off
Startup switch initial cash amount
turned "on"
System is
System System accepts Enter a legitimate
requesting cash System is on
Startup initial cash amount amount
amount
System output
Perform a should demonstrate
System Connection to the System has just
legitimate inquiry that a connection has
Startup bank is established been turned on
transaction been established to
the Bank
System is shut
System is on and
System down when the Activate the "off"
not servicing a System is off
Shutdown switch is turned switch
customer
"off"
System is started
System Activate the "on" System requests
when the switch is System is off
Startup switch initial cash amount
turned "on"
Card is ejected;
System is on and System displays an
System rejects an Insert an
Session not servicing a error screen;
unreadable card unreadable card
customer System is ready to
start a new session
System displays a
System accepts System is asking
Session Enter a PIN menu of transaction
customer's PIN for entry of PIN
types
System is asking
System allows
whether System displays a
multiple
Session customer wants Answer yes menu of transaction
transactions in one
another types
session
transaction
System is asking
Session ends when
whether System ejects card
customer chooses
Session customer wants Answer no and is ready to start
not to do another
another a new session
transaction
transaction
Individual types of
Transactio
transaction will be
n
tested below
Enter an incorrect
A readable card The Invalid PIN
Transactio System handles an PIN and then
has been Extension is
n invalid PIN properly attempt a
entered performed
transaction
System is started
System Activate the "on" System requests
when the switch is System is off
Startup switch initial cash amount
turned "on"
System asks
Menu of account System displays a
Withdraw customer to choose Choose checking
types is being menu of possible
al a dollar amount to account
displayed withdrawal amounts
withdraw
System dispenses
this amount of cash;
System prints a
Choose an correct receipt
System performs a System is amount that the showing amount and
legitimate displaying the system currently correct updated
Withdraw
withdrawal menu of has and which is balance;
al
transaction withdrawal not greater than System records
properly amounts the account transaction correctly
balance in the log (showing
both message to the
bank and approval
back)
System is started
System Activate the "on" System requests
when the switch is System is off
Startup switch initial cash amount
turned "on"
or not.
System displays an
A withdrawal
appropriate message
transaction can be
System is and offers customer
Withdraw cancelled by the Press "Cancel"
displaying menu the option of
al customer any time key
of account types choosing to do
prior to choosing
another transaction
the dollar amount
or not.
System displays an
A withdrawal
appropriate message
transaction can be System is
and offers customer
Withdraw cancelled by the displaying menu Press "Cancel"
the option of
al customer any time of dollar key
choosing to do
prior to choosing amounts
another transaction
the dollar amount
or not.
System is
System asks displaying a System requests that
Enter a legitimate
Deposit customer to insert request for the customer insert an
dollar amount
an envelope customer to type envelope
a dollar amount
System accepts
System performs a System is envelope;
legitimate deposit requesting that Insert an System prints a
Deposit
transaction customer insert envelope correct receipt
properly an envelope showing amount and
correct updated
System is started
System Activate the "on" System requests
when the switch is System is off
Startup switch initial cash amount
turned "on"
balance;
System records
transaction correctly
in the log (showing
message to the bank,
approval back, and
acceptance of the
envelope)
System displays an
A deposit
appropriate message
transaction can be
System is and offers customer
cancelled by the Press "Cancel"
Deposit displaying menu the option of
customer any time key
of account types choosing to do
prior to inserting
another transaction
an envelope
or not.
System displays an
A deposit
System is appropriate message
transaction can be
requesting and offers customer
cancelled by the Press "Cancel"
Deposit customer to the option of
customer any time key
enter a dollar choosing to do
prior to inserting
amount another transaction
an envelope
or not.
System displays an
A deposit
System is appropriate message
transaction can be
requesting and offers customer
cancelled by the Press "Cancel"
Deposit customer to the option of
customer any time key
insert an choosing to do
prior to inserting
envelope another transaction
an envelope
or not.
System is started
System Activate the "on" System requests
when the switch is System is off
Startup switch initial cash amount
turned "on"
System prints a
correct receipt
showing amount and
System is correct updated
System performs a
displaying a balance;
legitimate transfer Enter a legitimate
Transfer request for the System records
transaction dollar amount
customer to type transaction correctly
properly
a dollar amount in the log (showing
both message to the
bank and approval
back)
System displays an
A transfer
System is appropriate message
transaction can be
displaying menu and offers customer
cancelled by the Press "Cancel"
Transfer of account types the option of
customer any time key
specifying choosing to do
prior to entering
transfer from another transaction
dollar amount
or not.
System is started
System Activate the "on" System requests
when the switch is System is off
Startup switch initial cash amount
turned "on"
System displays an
A transfer
System is appropriate message
transaction can be
requesting and offers customer
cancelled by the Press "Cancel"
Transfer customer to the option of
customer any time key
enter a dollar choosing to do
prior to entering
amount another transaction
dollar amount
or not.
System prints a
correct receipt
showing correct
System performs a balance;
System is
legitimate inquiry Choose checking System records
Inquiry displaying menu
transaction account transaction correctly
of account types
properly in the log (showing
both message to the
bank and approval
back)
System displays an
An inquiry
appropriate message
transaction can be
System is and offers customer
cancelled by the Press "Cancel"
Inquiry displaying menu the option of
customer any time key
of account types choosing to do
prior to choosing
another transaction
an account
or not.
System is started
System Activate the "on" System requests
when the switch is System is off
Startup switch initial cash amount
turned "on"
Attempt an
inquiry
transaction on
the customer's
checking account
An incorrect PIN
A correctly re- has been re-
This transaction
Invalid PIN entered PIN is used entered and Perform another
completes
Extension for subsequent transaction transaction
successfully as well
transactions completed
normally
An appropriate
Incorrect re-entry Request to re- message is displayed
Invalid PIN Enter incorrect
of PIN is not enter PIN is and re-entry of the
Extension PIN
accepted being displayed PIN is again
requested
Enter incorrect
Correct re-entry of Request to re- Original transaction
Invalid PIN PIN the first time,
PIN on the second enter PIN is completes
Extension then correct PIN
try is accepted being displayed successfully
the second time
Enter incorrect
PIN the first time
Correct re-entry of Request to re- Original transaction
Invalid PIN and second
PIN on the third try enter PIN is completes
Extension times, then
is accepted being displayed successfully
correct PIN the
third time
System is started
System Activate the "on" System requests
when the switch is System is off
Startup switch initial cash amount
turned "on"
II. Design
6. Class descriptions
Class Responsibilities Collaboration
OperatorPanel
Start up when switch is turned on CashDispenser
NetworkToBank
Shut down when switch is turned off NetworkToBank
ATM
Start a new session when card is inserted by CustomerConsole
customer Session
Provide access to component parts for sessions
and transactions
Display a message
Display a prompt, accept a PIN from keyboard
Display a prompt and menu, accept a choice from
CustomerConsole keyboard
Display a prompt, accept a dollar amount from
keyboard
Respond to cancel key being pressed by customer
ATM
CardReader
Perform session use case Card
Session
CustomerConsole
Transaction
Update PIN value if customer has to re-enter it
ATM
CustomerConsole
Withdrawal
Allow customer to choose a type of transaction
Deposit
Transfer
Inquiry
ATM
CustomerConsole
Withdrawal
Transaction
Deposit
(Abstract class)
Transfer
Perform Transaction Use Case
Inquiry
Message
NetworkToBank
Receipt
ReceiptPrinter
CustomerConsole
Perform invalid PIN extension Session
CardReader
CustomerConsole
Perform operations peculiar to withdrawal CashDispenser
Withdrawal
transaction use case Message
Receipt
CustomerConsole
Perform operations peculiar to deposit Message
Deposit
transaction use case EnvelopeAcceptor
Receipt
CustomerConsole
Perform operations peculiar to transfer
Transfer Message
transaction use case
Receipt
CustomerConsole
Perform operations peculiar to inquiry transaction
Inquiry Message
use case
Receipt
In the case of the ATM system, one of the responsibilities of the ATM is to provide
access to its component parts for Session and Transaction objects; thus, Session and
Transaction have associations to ATM, which in turn has associations to the classes
representing the individual component parts. (Explicit "uses" links between Session and
Transaction, on the one hand, and the component parts of the ATM, on the other hand,
have been omitted from the diagram to avoid making it excessively cluttered.)
The need for the various classes in the diagram was discovered at various points in the
design process.
That is, OO design is not a "waterfall" process - discoveries made when doing detailed
design and coding can impact overall system design.
To prevent the diagram from becoming overly large, only the name of each class is
shown - the attribute and behavior "compartments" are shown in the detailed design,
but are omitted here.
Three of the objects we have identified have behavior that is sufficiently complex to
warrant developing a State Chart for them. (These are the objects that were identified
as the major controller objects.)
The object representing the machine itself (responsible for the System Startup
and Shutdown use cases)
Objects representing a customer session (one per session) (responsible for the
Session use case)
Objects representing an individual transaction (one per transaction) (responsible for
the Transaction use case, use cases for the specific types of transaction, and
Invalid PIN extension).
III. Implementation
1. Detailed Design
A major task of detailed design is to spell out, in detail, the attributes and methods
needed by each class (the second and third "compartments" of the representation for
each class in a class diagram.)
The methods needed by each class are implicit in the responsibilities assigned to the
class in the CRC cards, and become explicit in the Interaction Diagrams. A responsibility
listed for a class on its CRC card generally maps into a method or methods in the
detailed design. Likewise, any time an object belonging to a given class is shown as the
recipient of a message in either a Sequence or Collaboration Diagram, the class needs a
corresponding method. Many of the needed attributes are also either explicitly or
implicitly present in the diagrams; the need for others becomes evident as the code for
the class is being written. (Thus detailed design and coding are a "round trip" process -
detailed design dictates coding, and coding leads to elaboration of the detailed design.)
The class ATM is made an active class - that is, the ATM object has its own
thread. Using the Java thread facllity leads to defining a run() method in this
class whose body is executed by the ATM's thread. The fact that class ATM is
active is indicated in class diagrams by enclosing it in a heavier outline.
Certain signals initiate computation - e.g. the signals from the operator console
when the state of the switch is changed, or from the card reader when a card is
inserted. In the GUI simulation of the ATM, these signals are sent by the
"actionPerformed()" method of the appropriate GUI button; in a real ATM they
would be sent by the physical components themselves, which might then also
need to be active classes. (Note: this forms an exception to the rule that a
responsibility on a CRC card translates into a method in the design - in this case
the class sends a signal, rather than receiving it, so it does not need a method
directly corresponding to the responsibility.)
The Transaction hierarchy consists of the abstract class Transaction and four
concrete subclasses (Withdrawal, Deposit, Transfer and Inquiry). The class
Transaction has a "virtual constructor" called makeTransaction() which asks the
customer to choose a transaction type and then constructs and returns an object
ATM
- id: int
- place: String
- bankName: String
- bankAddress: InetAddress
- cardReader: CardReader
- cashDispenser: CashDispenser
- customerConsole: CustomerConsole
- envelopeAcceptor: EnvelopeAcceptor
- log: Log
- networkToBank: NetworkToBank
- operatorPanel: OperatorPanel
- receiptPrinter: ReceiptPrinter
- state: int
- switchOn: boolean
- cardInserted: boolean
+ run()
+ switchOn()
+ switchOff
+ cardInserted()
+ getID(): int
+ getPlace(): String
+ getBankName(): String
+ getCardReader(): CardReader
+ getCashDispenser(): CashDispenser
+ getCustomerConsole(): CustomerConsole
+ getEnvelopeAcceptor(): EnvelopeAcceptor
+ getLog(): Log
+ getNetworkToBank(): NetworkToBank
+ getOperatorPanel(): OperatorPanel
+ getReceiptPrinter(): ReceiptPrinter
- performStartup()
- performShutdown()
CardReader
- atm: ATM
+ CardReader(atm: ATM)
+ readCard(): Card
+ ejectCard()
+ retainCard()
CashDispenser
- log: Log
- cashOnHand: Money
+ CashDispenser(log: Log)
+ setInitialCash(initialCash: Money)
+ dispenseCash(amount: Money)
CustomerConsole
+ CustomerConsole()
+ display(message: String)
EnvelopeAcceptor
- log: Log
+ EnvelopeAcceptor(log: Log)
Log
+ Log()
+ logSend(message: Message)
+ logResponse(status: Status)
+ logCashDispensed(amount: Money)
+ logEnvelopeAccepted()
NetworkToBank
- log: Log
- bankAddress: InetAddress
+ openConnection()
+ closeConnection()
OperatorPanel
- atm: ATM
+ OperatorPanel(atm: ATM)
+ getInitialCash(): Money
ReceiptPrinter
+ ReceiptPrinter()
+ printReceipt(receipt: Receipt)
Session
- atm: ATM
- pin: int
- state: int
+ Session(atm: ATM)>
+ performSession()
+ setPIN(int pin)
Transaction
# atm: ATM
# session: Session
# card: Card
# pin: int
# serialNumber: int
# message: Message
# balances: Balances
- nextSerialNumber: int
- state: int
+ makeTransaction(atm: ATM, session: Session, card: Card, pin: int): Transaction throws
Cancelled
+ getSerialNumber(): int
Withdrawal
- from: int
- amount: Money
# completeTransaction(): Receipt
Deposit
- to: int
- amount: Money
Transfer
- from: int
- to: int
- amount: Money
# completeTransaction(): Receipt
Inquiry
- from: int
# completeTransaction(): Receipt
AccountInformation
Balances
- total: Money
- available: Money
+ Balances()
+ getTotal(): Money
+ getAvailable(): Money
Card
- number: int
+ Card(number: int)
+ getNumber(): int
Message
- messageCode: int
- card: Card
- pin: int
- serialNumber: int
- fromAccount: int
- toAccount: int
- amount: int
+ toString(): String
+ setPIN(pin: int)
+ getMessageCode(): int
+ getCard(): Card
+ getPIN(): int
+ getSerialNumber(): int
+ getFromAccount(): int
+ getToAccount(): int
+ getAmount(): Money
Money
- cents: long
+ Money(dollars: int)
+ Money(toCopy: Money)
+ toString(): String
+ add(amountToAdd: Money)
+ subtract(amountToSubtract: Money)
Receipt
- headingPortion: String []
# detailsPortion(): String []
- balancesPortion: String []
+ getLines(): Enumeration
Status
+ toString(): String
+ isSuccess(): boolean
+ isInvalidPIN(): boolean
+ getMessage(): String
Each of these classes, in turn, depends on the package atm which contains the class
ATM that represents the system as a whole, and the class Session that represents one
session. ATM depends on Session, and vice versa - since the ATM creates Sessions, and
each Session, in turn, uses the ATM to interact with the customer.
The subpackage physical contains the classes that represent the various physical
components of the ATM. For the purposes of this simulation, these are simulated by a
GUI. A real ATM would have quite different classes in this package - classes that actually
control its physical components. The class ATM makes use of these components, and
Session and the various kinds of transaction gain access to them through ATM to
actually perform the needed operations.
Finally, the package banking contains classes that represent the banking enterprise itself
and the information communicated back and forth between the ATM and the bank - i.e.
classes which might be the same in a totally different implementation of an ATM that
interacts with the same bank.
This is, of course, a simulation. However, most of the code that is specific to the
simulation resides in the package physical, plus the two top-level classes. Presumably,
the other classes and packages might be similar in a real system.