1、Page 1Chapter 8 Developing ATM Examplewith UMLPage 2ATM Requirements (1) The software to be designed will control a simulated automated teller machine (ATM) having: a magnetic stripe reader for reading an ATM card; a customer console (keyboard and display) for interaction with the customer; a slot f
2、or depositing envelopes; a dispenser for cash (in multiples of $20); a printer for printing customer receipts; a key-operated switch to allow an operator to start or stop the machine; and the ATM will communicate with the banks computer over an appropriate communication link.Page 3ATM Requirements (
3、2) 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. 2. A customer must be able to make a deposit to any account linked to the card, consisting of cash and
4、/or checks in an 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.Page 4ATM Requirements (3) A customer must be able to abort a transaction; The ATM will
5、communicate each transaction to the bank and obtain verification that it was allowed by the bank; The ATM will provide the customer with a printed receipt for each successful transaction; The ATM will have a key-operated switch that will allow an operator to start and stop the servicing of customers
6、; The ATM will also maintain an internal log of transactions.Page 5Use CaseInvalid PINWithdrawalDepositTransferInquirySystem StartupSystem ShutdownOperatorSessionCustomerTransactionBankPage 6System Startup Sequence Diagram : Operator Panel : ATM : Cash Dispenser : Network to BankSwitchOn( )performSt
7、artup( )getInitialCash( )InitialCash( )setInitialCash(InitialCash)OpenConnection( )Page 7System Shutdown Sequence Diagram : Operator Panel : ATM : Network to BankSwitchOff( )PerformShutdown( )CloseConnection( )Page 8Session Sequence Diagram : Card Reader : ATM : Session : Customer Console : Transact
8、ionCardInserted( )(this)performSession( )ReadCard( )cardreadPin( )pin(atm,this,card,pin)performTransaction( )doAgain while customer wants to perform transtionsejectCard( )Page 9Transaction Sequence DiagramPage 10Withdrawal Transaction CollaborationPage 11Deposit Transaction CollaborationPage 12Trans
9、fer Transaction CollaborationPage 13Inquiry Transaction CollaborationPage 14Invalid PIN Extension CollaborationPage 15Analysis ClassesOperator(from Use Case View).)Operator PanelCard ReaderATM(from atm)CardCustomer(from Use Case View).)LogCustomer ConsoleSessionReceipt PrinterCash DispenserEnvelope
10、AcceptorTransactionBank(from Use Case View).)Network to BankPage 16CRCClass ATMResponsibilities Start up when switch is turned on Shut down when switch is turned off Start a new session when card is inserted by customerCollaborators OperatorPanel CashDispenser NetworkToBank CustomerConsole SessionPa
11、ge 17CRCClass CardReaderResponsibilities Tell ATM when card is inserted Read information from card Eject card Retain cardCollaborators ATM CardBoundary/entity objectsPage 18CRCClass CashDispenserResponsibilities Keep track of cash on hand, starting with initial amount Report whether enough cash is a
12、vailable Dispense cashCollaborators LogBoundary/entity objectsPage 19CRCClass CustomerConsoleResponsibilities Display a message Display a prompt, accept a PIN from keyboard Display a prompt and menu, accept a choice from keyboard Display a prompt, accept a dollar amount from keyboard Respond to canc
13、el key being pressed by customerCollaboratorsBoundary/entity objectsPage 20CRCClass EnvelopeAcceptorResponsibilities Accept envelope from customer; report if timed out or cancelledCollaborators LogBoundary/entity objectsPage 21CRCClass LogResponsibilities Log messages sent to bank Log responses from
14、 bank Log dispensing of cash Log receiving an envelopeCollaboratorsBoundary/entity objectsPage 22CRCClass NetworkToBankResponsibilities Initiate connection to bank at startup Send message to bank and wait for response Terminate connection to bank at shutdownCollaborators Message Log Boundary/entity
15、objectsPage 23CRCClass OperatorPanelResponsibilities Inform ATM of changes to state of switch Allow operator to specify amount of initial cashCollaborators ATMBoundary/entity objectsPage 24CRCClass ReceiptPrinterResponsibilities Print receiptCollaborators ReceiptBoundary/entity objectsPage 25CRCClas
16、s SessionResponsibilities Perform session use case Update PIN value if customer has to re-enter itCollaborators ATM CardReader Card CustomerConsole Transaction Control objectsPage 26CRCAbstract Class TransactionResponsibilities Allow customer to choose a type of transaction Perform Transaction Use C
17、ase Perform invalid PIN extension Collaborators ATM CustomerConsole Withdrawal Transfer Deposit Inquiry Message NetworkToBank ReceiptPrinter Session CardReaderControl objectsPage 27CRCClass WithdrawalResponsibilities Perform operations peculiar to withdrawal transaction use case Collaborators Custom
18、erConsole CashDispenser Message Receipt Control objectsPage 28CRCClass DepositResponsibilities Perform operations peculiar to deposit transaction use case Collaborators CustomerConsole Message EnvelopeAcceptor ReceiptControl objectsPage 29CRCClass TransferResponsibilities Perform operations peculiar
19、 to transfer transaction use case Collaborators CustomerConsole Message ReceiptControl objectsPage 30CRCClass InquiryResponsibilities Perform operations peculiar to inquiry transaction use case Collaborators CustomerConsole Message Receiptcontrol objectsPage 31CRCClass BalancesResponsibilities Repre
20、sent account balance information returned by bankCollaboratorsentity objectsPage 32CRCClass CardResponsibilities Represent information encoded on customers ATM cardCollaboratorsentity objectsPage 33CRCClass MessageResponsibilities Represent information to be sent over network to bankCollaboratorsent
21、ity objectsPage 34CRCClass ReceiptResponsibilities Represent information to be printed on a receiptCollaboratorsentity objectsPage 35CRCClass StatusResponsibilities Represent transaction status information returned by bankCollaboratorsentity objectsPage 36Class DiagramPage 37Statecharts for Control
22、Objects: ATMOFFentry/ display Not availableIDLEentry/ display please insert cardswitch turned on / perform startupSERVING CUSTOMERswitch turned off / perform shutdowncard inserted / create sessionsession completed or abortedPage 38Statecharts for control objects: SessionREADING CARDREADING PINCHOOSI
23、NG TRANSACTIONPERFORMING TRANSACTIONEJECTING CARDCustomer finishedCustomer wants to anotherAborted due to too many invalid PINS-card retainedtransaction chosenCancel pressedPIN read successfullyCancel pressedCard read successfullyCard not readable / display Card not readablePage 39Statecharts for co
24、ntrol objects: TransactionGETTING SPECIFICSSENDING TO BANKHANDLING INVALID PINCOMPLETING TRANSACTIONPRINTING RECEIPTASKING IF CUSTOMER WANTS ANOTHERNot cancelledCancelledInvalid PINApprovedDisapproved( except Invalid PIN )Specifics enteredCancelledApprovedDisapproved(except Invalid PIN) or Cancelled
25、Too many invalid PINsPage 40Package DiagramATMMainATMAppletatmSessionATM(from atm)transactionPhysicalBanking+CardReader+CashDispenser+CustomerConsole+EnvelopeAcceptor+Log+NetworkToBank+OperatorPanel+ReceiptPrinter+Transaction+Withdrawal+Deposit+Transfer+Inquiry+AccountInformation+Balances+Card+Messa
26、ge+Money+Receipt+StatusPage 41Detail Design of ClassesATM - id: int - place: String - bankName: String - bankAddress: InetAddress - cardReader: CardReader - cashDispenser: CashDispenser - customerConsole: CustomerConsole - envelopeAcceptor: EnvelopeAcceptor - log: Log - networkToBank: NetworkToBank
27、- operatorPanel: OperatorPanel - receiptPrinter: ReceiptPrinter - state: int - switchOn: boolean - cardInserted: boolean - OFF_STATE: final int - IDLE_STATE: final int - SERVING_CUSTOMER_STATE: final int Page 42Detail Design of Classes-+ ATM(id: int, place: String, bankName: String, bankAddress: Ine
28、tAddress) + run() + switchOn() + switchOff + cardInserted() + getID(): int + getPlace(): String + getBankName(): String + getCardReader(): CardReader + getCashDispenser(): CashDispenser + getCustomerConsole(): CustomerConsole + getEnvelopeAcceptor(): EnvelopeAcceptor + getLog(): Log + getNetworkToBa
29、nk(): NetworkToBank + getOperatorPanel(): OperatorPanel + getReceiptPrinter(): ReceiptPrinter - performStartup() - performShutdown() Page 43Detail Design of ClassesCardReader - - atm: ATM - + CardReader(atm: ATM) + readCard(): Card + ejectCard() + retainCard() Page 44Detail Design of ClassesCashDisp
30、enser - - log: Log - cashOnHand: Money - + CashDispenser(log: Log) + setInitialCash(initialCash: Money) + checkCashOnHand(amount: Money): boolean + dispenseCash(amount: Money) Page 45Detail Design of ClassesCustomerConsole - - + CustomerConsole() + display(message: String) + readPIN(prompt: String):
31、 int throws Cancelled + readMenuChoice(prompt: String, menu: String ): int throws Cancelled + readAmount(prompt: String): Money throws Cancelled Page 46Detail Design of ClassesEnvelopeAcceptor - - log: Log - + EnvelopeAcceptor(log: Log) + acceptEnvelope() throws Cancelled Page 47Detail Design of Cla
32、ssesLog - - + Log() + logSend(message: Message) + logResponse(status: Status) + logCashDispensed(amount: Money) + logEnvelopeAccepted() Page 48Detail Design of ClassesNetworkToBank - - log: Log - bankAddress: InetAddress - + NetworkToBank(log: Log, bankAddress: InetAddress) + openConnection() + clos
33、eConnection() + sendMessage(message: Message, out balances: Balances): Status Page 49Detail Design of ClassesOperatorPanel - - atm: ATM - + OperatorPanel(atm: ATM) + getInitialCash(): Money Page 50Detail Design of ClassesReceiptPrinter - - + ReceiptPrinter() + printReceipt(receipt: Receipt) Page 51D
34、etail Design of ClassesSession - atm: ATM - pin: int - state: int - READING_CARD_STATE: final int - READING_PIN_STATE: final int - CHOOSING_TRANSACTION_STATE: final int - PERFORMING_TRANSACTION_STATE: final int - EJECTING_CARD_STATE: final int -FINAL_STATE: final int - + Session(atm: ATM) + performS
35、ession() + setPIN(int pin)Page 52Detail Design of ClassesTransaction -# atm: ATM # session: Session # card: Card # pin: String# serialNumber: int # message: Message # balances: Balances - TRANSACTION_TYPES_MENU: final String - nextSerialNumber: int - state: int - GETTING_SPECIFICS_STATE: final int -
36、 SENDING_TO_BANK_STATE: final int - INVALID_PIN_STATE: final int - COMPLETING_TRANSACTION_STATE: final int - PRINTING_RECEIPT_STATE: final int - ASKING_DO_ANOTHER_STATE: final int Page 53Detail Design of Classes- # Transaction(atm: ATM, session: Session, card: Card, pin: int) + makeTransaction(atm:
37、ATM, session: Session, card: Card, pin: int): Transaction throws Cancelled + performTransaction(): boolean throws CardRetained + performInvalidPinExtension(): Status throws Cancelled, CardRetained + getSerialNumber(): int # getSpecificsFromCustomer(): Message throws Cancelled # completeTransaction()
38、: Receipt throws Cancelled Page 54Detail Design of ClassesWithdrawal - - from: int - amount: Money - + Withdrawal(atm: ATM, session: Session, card: Card, pin: int) # getSpecificsFromCustomer(): Message throws Cancelled # completeTransaction(): ReceiptPage 55Detail Design of ClassesDeposit - - to: in
39、t - amount: Money - + Deposit(atm: ATM, session: Session, card: Card, pin: int) # getSpecificsFromCustomer(): Message throws Cancelled # completeTransaction(): Receipt throws Cancelled Page 56Detail Design of ClassesTransfer - - from: int - to: int - amount: Money - + Transfer(atm: ATM, session: Ses
40、sion, card: Card, pin: int) # getSpecificsFromCustomer(): Message throws Cancelled # completeTransaction(): Receipt Page 57Detail Design of ClassesInquiry - - from: int - + Inquiry(atm: ATM, session: Session, card: Card, pin: int) # getSpecificsFromCustomer(): Message throws Cancelled # completeTran
41、saction(): Receipt Page 58Detail Design of ClassesAccountInformation - + ACCOUNT_NAMES: final String + ACCOUNT_ABBREVIATIONS: final String Page 59Detail Design of ClassesBalances - - total: Money - available: Money - + Balances() + setBalances(total: Money, available: Money) + getTotal(): Money + ge
42、tAvailable(): MoneyPage 60Detail Design of ClassesCard - - number: int - + Card(number: int) + getNumber(): int Page 61Detail Design of ClassesMessage - + WITHDRAWAL: final int + INITIATE_DEPOSIT: final int + COMPLETE_DEPOSIT: final int + TRANSFER: final int + INQUIRY: final int - messageCode: int -
43、 card: Card - pin: String - serialNumber: int - fromAccount: int - toAccount: int - amount: int Page 62Detail Design of Classes- + Message(messageCode: int, cardNumber: Card, pin: int, serialNumber: int, fromAccount: int, toAccount: int, amount: Money) + toString(): String + setPIN(pin: int) + getMe
44、ssageCode(): int + getCard(): Card + getPIN(): String + getSerialNumber(): int + getFromAccount(): int + getToAccount(): int + getAmount(): Money Page 63Detail Design of ClassesMoney - - cents: long - + Money(dollars: int) + Money(dollars: int, cents: int) + Money(toCopy: Money) + toString(): String
45、 + add(amountToAdd: Money) + subtract(amountToSubtract: Money) + lessEqual(compareTo: Money): booleanPage 64Detail Design of ClassesReceipt - - headingPortion: String # detailsPortion(): String - balancesPortion: String - # Receipt(atm: ATM, card: Card, transaction: Transaction, balances: Balances)
46、+ getLines(): Enumeration Page 65Detail Design of ClassesStatus - - + toString(): String + isSuccess(): boolean + isInvalidPIN(): boolean + getMessage(): String Page 66Codepackage banking;public class Card public Card(int number) this.number = number; public int getNumber() return number; /* Card nu
47、mber encoded on the card */ private int number;Page 67Codepackage banking;/* The static members of this class incorporate information about accounts * offered by the bank. Actual communication with the bank uses account type * numbers - e.g. 0 represents the first type of account listed. */public cl
48、ass AccountInformation /* Names for accounts to be offered in menu to customer */ public static final String ACCOUNT_NAMES = Checking, Savings, Money Market ; /* Abbreviations for account names to be printed on receipts. */ public static final String ACCOUNT_ABBREVIATIONS = CHKG, SVGS, MMKT ; Page 6
49、8Codepackage banking;public class Balances public Balances() public void setBalances(Money total, Money available) this.total = total; this.available = available; public Money getTotal() return total; public Money getAvailable() return available; private Money total; private Money available;Page 69C
50、odepackage atm.physical;import banking.Money;import simulation.Simulation;public class CashDispenser public CashDispenser(Log log) this.log = log; cashOnHand = new Money(0); public void setInitialCash(Money initialCash) cashOnHand = initialCash; public boolean checkCashOnHand(Money amount) return am