Atm Simulator

36
ATM Simulator

description

Java Explanation of ATM Assignment.

Transcript of Atm Simulator

Page 1: Atm Simulator

ATM Simulator

Page 2: Atm Simulator

Software Life Cycle

Elicit requirements describe use cases

Create a specification Design

structure (classes and their relations) behavior state

Implement Deploy Maintain & Enhance

What about testing and documentation? Why aren't they listed as steps in the life cycle?

Page 3: Atm Simulator

Unified Software Process

Iterative and Incremental Perform multiple iterations Incrementally (in each iteration) add functionality

Start with most important use cases or requirements

Page 4: Atm Simulator

ATM Simulator

Design and implement an ATM Simulator that simulates the functions of a real ATM.

The ATM will support PIN authentication, balance inquiry, and withdrawal. If time permits, we will add deposit and transfers.

Goals Practice software development methodology using

UML, interfaces, and inheritance. Use O-O design to limit the complexity of

implementation.

Page 5: Atm Simulator

ATM user interface (sort of)

Our Simulator will have more buttons than this.

Page 6: Atm Simulator

ATM main menu (sort of)

Our Simulator may have more menu options than this.

Page 7: Atm Simulator

ATM Phase 1

Develop requirements for an ATM with withdrawal and balance inquiry.

Implement a simple ATM engine and console interface. Determine what public methods (interface) are needed

for an ATM U.I. Determine what services are needed from the Bank

subsystem. For this phase, we will use a dummy Bank. It approves

all requests.

Page 8: Atm Simulator

ATM Use Case: withdraw (1)

Description: Customer withdraws money from account

Actors:Bank customer with ATM card

Steps:

1. ATM machine displays greeting.

2. Customer inserts card.

3. ATM reads card and prompts customer for PIN.

4. Customer enters PIN.

5. ATM contacts Bank to verify customer's PIN.

6. Bank verifies PIN.

7. ATM prompts customer for transaction type.

8. Customer chooses withdraw.

Page 9: Atm Simulator

ATM Use Case: withdraw (2)

9. ATM asks customer to enter amount to withdraw.

10. Customer enters amount.

11. ATM verifies it has bills to provide this amount.

12. ATM contacts Bank to verify customer can withdraw the requested amount.

13. Bank verifies withdraw and debits customer's acct.

14. ATM dispenses amount and prompts customer to take money.

15. Customer takes money.

Page 10: Atm Simulator

ATM Use Case: withdraw (3)

16. ATM prints receipt and prompts customer to take it.

17. Customer take receipt.

18. ATM asks customer if he wants another transaction.

19. Customer selects "no" option.

20. ATM returns customer's card.

21. Customer takes card.

Page 11: Atm Simulator

ATM Use Case: withdraw (4)

Extensions and Alternatives:

Scenario: step 3, ATM cannot read valid acct number from ATM card.

3a. ATM prints message describing problem.

3b. execute steps 20-21 of main course.

Scenario: step 6. Bank indicates PIN is incorrect.

6a. if count of failed PIN attempts is < 3, goto step 3. Otherwise, execute steps 20-21 of main course.

Scenario: step 11, customer's entry is not a number or ATM cannot dispense the requested amount.

11a. Display message describing problem.

11b. Return to step 9.

Page 12: Atm Simulator

ATM Use Case: withdraw (5)

Extensions and Alternatives:

Scenario: at any time after authentication the customer presses CANCEL button.

__a. Return customer's card and prompt him to take it.

Extension: a customer may have more than one account. Enable customer to choose account for withdrawal.

Issue: if customer presses CANCEL should ATM return card or return to option's menu?

Issue: after 3 failed PIN attempts should ATM notify Bank for security reasons? I.e., temporarily lock-out this ATM card.

Page 13: Atm Simulator

ATM Use Case: balance inquiry (1)

Description: Customer inquires his account balance

Actors:Bank customer with ATM card

Steps:

1. ATM machine displays greeting.

2. Customer inserts card.

3. ATM reads card and prompts customer for PIN.

4. Customer enters PIN.

5. ATM contacts Bank to verify customer's PIN.

6. Bank verifies PIN.

7. ATM prompts customer for transaction type.

8. Customer chooses balance inquiry.

Page 14: Atm Simulator

ATM Use Case: balance inquiry (2)

To be completed.

Page 15: Atm Simulator

ATM Use Case: deposit (1)

Description: Customer deposits funds (cash or checks) in account using a deposit envelop

Actors: Bank customer with ATM card and funds

Steps:

1. ATM machine displays greeting.

2. Customer inserts card.

3. ATM reads card and prompts customer for PIN.

4. Customer enters PIN.

5. ATM contacts Bank to verify customer's PIN.

6. Bank verifies PIN.

7. ATM prompts customer for transaction type.

8. Customer chooses deposit.

Page 16: Atm Simulator

ATM Use Case: deposit (2)

To be completed.

Page 17: Atm Simulator

Use Case Factoring and Diagram

Factor out common behavior from the use cases. Steps 1 - 7 are the same in all use cases. Displaying menu and choosing an option is another

common task.

Draw a Use Case Diagram. Helpful for visually actors and components. Free UML editor: ArgoUML (argouml.tigris.org)

Page 18: Atm Simulator

Specification

Use cases help you identify what a system should do. A software specification document clarifies what the

program should do. This is usually part of a software contract. Can be formal or informal, but must be written.

Specification will help identify classes and responsibilities.

Page 19: Atm Simulator

Structure: identify classes

Page 20: Atm Simulator

Nouns in the requirements document.

Nouns and noun phrases in the requirements document

bank money / funds account number

ATM screen PIN

user keypad bank database

customer cash dispenser balance inquiry

transaction $20 bill / cash withdrawal

account deposit slot deposit

balance deposit envelope

Source: Dietel & Dietel, Java, How to Program.

Page 21: Atm Simulator

Modeling Classes

UML class diagrams Allows suppression of class attributes and

operations Called an elided diagram

Solid line that connects two classes represents an association

numbers near end of each line are multiplicity values

Page 22: Atm Simulator

Class Diagram with Association

Attributes and methods are omitted ("elided") In early design phase, concentrate on identifying

classes and responsibilities first. numbers near end of each line are multiplicity

Page 23: Atm Simulator

Modeling Classes

UML class diagrams Solid diamonds attached to association lines

indicate a composition relationship Hollow diamonds indicate aggregation – a

weaker form of composition

Page 24: Atm Simulator

Class diagram for ATM U.I.

Association and Composition Used when one object "owns" or controls another Solid diamonds indicate composition relationship:

the ATM is composed of these parts; the parts do not exist without the whole (ATM)

Source: Dietel & Dietel, Java, How to Program

Page 25: Atm Simulator

Class diagram for ATM U.I. Association and Composition

Hollow (open) diamonds indicate association relationship: the whole possesses these parts, but the parts can exist without the whole.

Examples: a Stack has a LinkedList, a Mailbox has Messages

LinkedList

addFirstaddLastaddAfterremoveFirstremoveLastdeleteisEmpty

Stack

pushpopisEmpty

Page 26: Atm Simulator

Diagram for ATM with WithdrawalHowever, in our implementation we will separate UI from ATM functionality (deposit, withdraw, etc).

Source: Dietel & Dietel, Java, How to Program

Page 27: Atm Simulator

ATM with Separate User Interface Separate ATM user interface from the class(es) that provide ATM

functionality. user interface is screen, keypad, card slot, money dispenser, etc.

Create a Java interface to define public methods.

<<interface>>

ATMInterface

displayMessage ATMsim

deposit( )withdraw( )balanceInquiry( )

ATM UI

atmUI: ATMInterface

ATM( atmUI )

<<ATM Logic Engine>>

Page 28: Atm Simulator

ATM with Separate User Interface Benefits of using an interface:

you can change the actual user interface without changing any other parts of the system

Example:

a class implementing ATMInterface is responsible for displaying messages, accepting input from keypad, reading ATM card, returning ATM card, printing receipts, and dispensing cash

for a GUI interface, we may decide to divide these responsibilities into separate classes

one main class, called a Façade, acts as interface between ATM Engine and the various component classes.

Page 29: Atm Simulator

ATM with Separate User Interface Separate ATM user interface from the class(es) that provide ATM

functionality. user interface is screen, keypad, card slot, money dispenser, etc.

Create a Java interface to define public methods.

<<interface>>

ATMInterfacedisplayMessage ATM

deposit( )withdraw( )balanceInquiry( )

ATM GUI

atmUI: ATMInterface

ATM( atmUI )

<<ATM Logic Engine>>

Keypad

Screen

Card Slot

Page 30: Atm Simulator

Identify Class Responsibilities What are the main responsibilities of each class?

responsibilities are usually activities or actions if a class doesn't have any responsibilities, it can be eliminated

Example: initially write a console-based U.I.

Later we will write a GUI for ATM. multiple programmers can work on different parts of project

simultaneously helps to limit complexity and enforce good design

Page 31: Atm Simulator

Identifying Class Attributes

Identifying attributes Look for descriptive nouns and phrases in the

requirements document Eliminate some nouns:

(1) redundant, (2) abstract, (3) describe instances, (4) outside the problem boundary (domain)

Create attributes and assign them to classes

Page 32: Atm Simulator

Possible Attributes for ATM System

Page 33: Atm Simulator

First Iteration

Ignore the Bank and Account components. No GUI interface. Design a basic ATM engine, ATM interface (Java

interface), and console-based UI. Handle only a few transactions: withdraw, fast cash.

Page 34: Atm Simulator

Design: use a state chart

A state chart diagram can help understand behavior.

Wait for an ATM user

Transaction Loop

Start

error

Fail < 3 times

Verify ATM card

Verify PIN Code

Fail 3 times or Cancel

End Session /Return ATM card

[Invalid/unreadable card]

Page 35: Atm Simulator

Transaction Loop

UML state chart diagram for transaction loop

Display Transactions Menu

Deposit dialog Withdraw dialogShow Balance

get deposit envelop

error

OK

Transaction Loop

END

Exit

OK

OK

verify input andavailable balance

fail

OK

OK

cancelcancel

"Deposit" action "Inquiry" action "Withdraw" action

Page 36: Atm Simulator

Second Iteration (due Tues 6/9/2005)

implement the ATMInterface.java as a console interface.

write an ATM simulator that does this: read ATM card and PIN display transaction menu handle withdraw, fast cash, and balance inquiry use the ATMInterface for all I/O

Design a Transaction class to encapsulate transactions.