Top Banner
ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed. ftp://mail.im.tku.edu.tw/seke/jhtp7/ examples/ch01/ATM/ ftp://mail.im.tku.edu.tw/seke/jhtp7/ appendix/
100

ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

Dec 30, 2015

Download

Documents

Jemimah Price
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

ATM Case StudyChapter 1-10 Optional Sections

Java How To Program 7th Ed.ftp://mail.im.tku.edu.tw/seke/jhtp7/examples/ch01/ATM/

ftp://mail.im.tku.edu.tw/seke/jhtp7/appendix/jhtp7_appM_CaseStudyCode.pdf

http://mail.im.tku.edu.tw/~seke/course12/oop/atm/atm.ziphttp://mail.im.tku.edu.tw/~seke/course12/oop/atm/atm.ppt

Page 2: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

2

1.15 Test-Driving a Java Application

• Test-driving the ATM application– Check system setup– Locate the ATM application (Fig. 1.2)– Run the ATM application (Fig. 1.3)– Enter an account number (Fig. 1.4)– Enter a PIN (Fig. 1.5)– View the account balance (Fig. 1.6)– Withdraw money from the account (Fig. 1.7)– Confirm that the account information has been updated (Fig.

1.8)– End the transaction (Fig. 1.9)– Exit the ATM application

• Additional applications (Fig. 1.10)

Chapter 1

Page 3: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

3

Fig. 1.2 | Opening a Windows XP Command Prompt and changing directories.

Using the cd command to

change directories File location of the ATM application

Page 4: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

4

Fig. 1.3 | Using the java command to execute the ATM application.

Page 5: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

5

Fig. 1.4 | Prompting the user for an account number.

ATM welcome message Enter account number prompt

Page 6: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

6

Fig. 1.5 | Entering a valid PIN number and displaying the ATM application's main menu.

Enter valid PIN ATM main menu

Page 7: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

7

Fig. 1.6 | ATM application displaying user account balance information.

Account balance information

Page 8: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

8

Fig. 1.7 | Withdrawing money from the account and returning to the main menu.

ATM withdrawal menu

Page 9: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

9

Fig. 1.8 | Checking new balance.

Confirming updated account balance information after withdrawal transaction

Page 10: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

10

Fig. 1.9 | Ending an ATM transaction session.

ATM goodbye message

Account number prompt for next user

Page 11: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

11

Fig. 1.10 | Examples of additional Java applications found in Java How to Program, 6/e.

Application Name Chapter Location Commands to Run

Tic-Tac-Toe Chapters 8 and 24 cd C:\examples\ch01\Tic-Tac-Toe java TicTacToeTest

Guessing Game Chapter 11 cd C:\examples\ch01\GuessGame java GuessGame

Logo Animator Chapter 21 cd C:\examples\ch01\LogoAnimator java LogoAnimator

Bouncing Ball Chapter 23 cd C:\examples\ch01\BouncingBall java BouncingBall

Page 12: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

121.16 Software Engineering Case Study: Introduction to Object Technology and the UML (Required)

• Object orientation

• Unified Modeling Language (UML)– Graphical language that uses common notation

– Allows developers to represent object-oriented designs

Page 13: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

13

1.16 Software Engineering Case Study (Cont.)

• Objects– Reusable software components that model real-world items

– Look all around you• People, animals, plants, cars, etc.

– Attributes• Size, shape, color, weight, etc.

– Behaviors• Babies cry, crawl, sleep, etc.

Page 14: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

14

1.16 Software Engineering Case Study (Cont.)

• Object-oriented design (OOD)– Models software in terms similar to those used to describe real-

world objects– Class relationships– Inheritance relationships– Models communication among objects– Encapsulates attributes and operations (behaviors)

• Information hiding• Communication through well-defined interfaces

• Object-oriented language– Programming in object-oriented languages is called object-

oriented programming (OOP)– Java

Page 15: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

15

1.16 Software Engineering Case Study (Cont.)

• Classes are to objects as blueprints are to houses

• Associations– Relationships between classes

• Packaging software in classes facilitates reuse

Page 16: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

16

1.16 Software Engineering Case Study (Cont.)

• Object-Oriented Analysis and Design (OOA/D)– Essential for large programs

– Analyze program requirements, then develop a design

– UML• Unified Modeling Language

• Standard for designing object-oriented systems

Page 17: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

17

1.16 Software Engineering Case Study (Cont.)

• History of the UML– Need developed for process with which to approach

OOA/D

– Brainchild of Booch, Rumbaugh and Jacobson

– Object Management Group (OMG) supervised

– Version 2 is current version

Page 18: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

18

1.16 Software Engineering Case Study (Cont.)

• UML– Graphical representation scheme

– Enables developers to model object-oriented systems

– Flexible and extensible

Page 19: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

19

1.17 Web 2.0

• Web use exploded in mid-to-late 1990s

• Dot com economic bust hit in the early 2000s

• Resurgence in 2004 with Web 2.0– First Web 2.0 conference

– Google widely regarded as signature company of Web 2.0

– Web services enable Web 2.0

Page 20: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

20

1.17 Web 2.0 (cont.)

• Ajax– Term popularized in 2005

– Group of technologies and programming techniques in use since the late 1990s

– Helps Internet-based applications perform like desktop application

Page 21: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

21

1.17 Web 2.0 (cont.)

• Blogs– Websites that are like online diaries

– About 60 million of them at the time of this writing

– Blogosphere—Collection of all blogs and the blogging community

– Technorati—a leading blog search engine

• RSS feeds– Enable sites to push information to subscribers

– Commonly used to deliver blog postings

Page 22: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

22

1.17 Web 2.0 (cont.)

• Web 3.0– Next generation web

– Also known as the semantic web

– Web 1.0 mostly HTML based

– Web 2.0 making increasing use of XML (e.g., RSS feeds)

– Web 3.0 will make extensive use of XML to add meaning to content

Page 23: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

23

1.18 Software Technologies

• Agile Software Development– Methodologies for developing software quickly with fewer

resources

• Extreme Programming (XP)– One of many agile development methodologies– Release software frequently in small increments to

encourage user feedback– Programmers work in pairs at one computer– Immediate code review– All team programmers able to work on any part of code

Page 24: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

24

1.18 Software Technologies (cont.)

• Refactoring– Reworking code to make cleaner/easier to maintain

– Widely used in agile development methodologies

– Many tools available

• Design patterns– Proven architectures for constructing flexible/maintainable

object-oriented software

Page 25: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

25

1.18 Software Technologies (cont.)

• Game programming– Game business is larger than first run movie business

– College courses and majors now devoted to sophisticated game-programming techniques

Page 26: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

26

1.18 Software Technologies (cont.)

• Open source software– Individuals and companies contribute to developing,

maintaining and evolving software in exchange for the right to use that software for their own purposes, typically at no charge

– Code typically scrutinized by much larger audiences, so bugs get removed faster

– Java now open source

– Some open source organizations• Eclipse Foundation, Mozilla Foundation, Apache Software

Foundation, SourceForge

Page 27: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

27

1.18 Software Technologies (cont.)

• Linux– Open source operating system– One of the greatest successes of the open source movement

• MySQL– an open source database management system

• PHP – most popular open source server-side Internet “scripting”

language for developing Internet-based applications

• LAMP—Linux, Apache, MySQL and PHP (or Perl or Python)

– An acronym for the set of open source technologies that many developers used to build web applications

Page 28: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

28

1.18 Software Technologies (cont.)

• Ruby on Rails– Combines the scripting language Ruby with the Rails web

application framework developed by 37Signals

– Many Ruby on Rails developers report significant productivity gains over using other languages when developing database-intensive web applications

– Getting Real (gettingreal.37signals.com/toc.php)• a must read for today’s web application developers

Page 29: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

29

1.18 Software Technologies (cont.)

• Software generally viewed as a product– You buy a software package from a software vendor, then install

that software on your computer and run it as needed

– Upgrade process cumbersome and expensive

• Software as a service (SAAS)– Software runs on servers elsewhere on the Internet

– When server is updated, all clients worldwide see the new capabilities

– Access the software through a browser

– Salesforce.com, Google and Microsoft’s Office Live and Windows Live all offer SAAS.

Page 30: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

30

2.9 (Optional) Software Engineering Case Study: Examining the Requirements Document

• Object-oriented design (OOD) process using UML

– Chapters 3 to 8, 10

• Object-oriented programming (OOP) implementation

– Appendix J

Chapter 2

Page 31: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

31

2.9 (Optional) Software Engineering Case Study (Cont.)

• Requirements Document– New automated teller machine (ATM)

– Allows basic financial transaction• View balance, withdraw cash, deposit funds

– User interface• Display screen, keypad, cash dispenser, deposit slot

– ATM session• Authenticate user, execute financial transaction

Page 32: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

32

Fig. 2.17 | Automated teller machine user interface.

Page 33: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

33

Fig. 2.18 | ATM main menu.

Page 34: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

34

Fig. 2.19 | ATM withdrawal menu.

Page 35: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

35

2.9 (Optional) Software Engineering Case Study (Cont.)

• Analyzing the ATM System– Requirements gathering

– Software life cycle• Waterfall model

• Interactive model

– Use case modeling

• Use case Diagram– Model the interactions between clients and its use cases

– Actor• External entity

Page 36: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

36

Fig. 2.20 | Use case diagram for the ATM system from the user's perspective.

Page 37: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

37

Fig. 2.21 | Use case diagram for a modified version of our ATM system that also allows users to transfer money between accounts.

Page 38: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

38

2.9 (Optional) Software Engineering Case Study (Cont.)

• UML diagram types– Model system structure

• Class diagram

– Models classes, or “building blocks” of a system

– screen, keypad, cash dispenser, deposit slot.

Page 39: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

39

2.9 (Optional) Software Engineering Case Study (Cont.)

– Model system behavior• Use case diagrams

– Model interactions between user and a system• State machine diagrams

– Model the ways in which an object changes state • Activity diagrams

– Models an object’s activity during program execution• Communication diagrams (collaboration diagrams)

– Models the interactions among objects– Emphasize what interactions occur

• Sequence diagrams – Models the interactions among objects– Emphasize when interactions occur

Page 40: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

40

3.10 (Optional) Software Engineering Case Study: Identifying the Classes in a Requirements Document

• Begin designing the ATM system– Analyze the nouns and noun phrases

– Introduce UML class diagrams

Chapter 3

Page 41: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

41

Identifying the Classes in a System

• Key nouns and noun phrases in requirements document

– Some are attributes of other classes

– Some do not correspond to parts of the system

– Some are classes• To be represented by UML class diagrams

Page 42: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

42

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

Fig. 3.19 | Nouns and noun phrases in the requirements document.

Page 43: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

43

Modeling Classes

• UML class diagrams– Top compartment contains name of the class

– Middle compartment contains class’s attributes or instance variables

– Bottom compartment contains class’s operations or methods

Page 44: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

44

Fig. 3.20 | Representing a class in the UML using a class diagram.

Page 45: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

45

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 46: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

46

Fig. 3.21 | Class diagram showing an association among classes.

Page 47: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

47

Fig. 3.22 | Multiplicity types.

Symbol Meaning

0 None

1 One

m An integer value

0..1 Zero or one

m, n m or n

m..n At least m, but not more than n

* Any non-negative integer (zero or more)

0..* Zero or more (identical to *)

1..* One or more

Page 48: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

48

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 49: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

49

Fig. 3.23 | Class diagram showing composition relationships.

Page 50: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

50

Fig. 3.24 | Class diagram for the ATM system model.

Page 51: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

51

Fig. 3.25 | Class diagram showing composition relationships of a class Car.

Page 52: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

52

Fig. 3.26 | Class diagram for the ATM system model including class Deposit.

Page 53: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

53

Fig. 4.23 | Descriptive words and phrases from the ATM requirements.

Class Descriptive words and phrases

ATM user is authenticated

BalanceInquiry account number

Withdrawal account number amount

Deposit account number amount

BankDatabase [no descriptive words or phrases]

Account account number PIN Balance

Screen [no descriptive words or phrases] Keypad [no descriptive words or phrases] CashDispenser begins each day loaded with 500 $20 bills

DepositSlot [no descriptive words or phrases]

Chapter 4

Page 54: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

54

Software Engineering Observation 4.6

At early stages in the design process, classes often lack attributes (and operations). Such classes should not be eliminated, however, because attributes (and operations) may become evident in the later phases of design and implementation.

Page 55: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

554.15  Identifying Class Attributes

• Identifying attributes– Look for descriptive words and phrases in the

requirements document

– Create attributes and assign them to classes

– Each attribute is given an attribute type

– Some attributes may have an initial value

– Some classes may end up without any attributes• Additional attributes may be added later on as the design

and implementation process continues

– Reference-type attributes are modeled more clearly as associations

Page 56: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

56

Fig. 4.24 | Classes with attributes.

Page 57: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

57

5.11 (Optional) Software Engineering Case Study: Identifying Object’s State and Activities

• State Machine Diagrams– Commonly called state diagram

– Model several states of an object

– Show under what circumstances the object changes state

– Focus on system behavior

– UML representation• State

– Rounded rectangle

• Initial state

– Solid circle

• Transitions

– Arrows with stick arrowheads

Chapter 5

Page 58: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

58

Fig. 5.29 | State diagram for the ATM object.

Page 59: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

59

Software Engineering Observation 5.5

Software designers do not generally create state diagrams showing every possible state and state transition for all attributes—there are simply too many of them. State diagrams typically show only key states and state transitions.

Page 60: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

60

5.11 (Optional) Software Engineering Case Study (Cont.)

• Activity Diagrams– Focus on system behavior

– Model an object’s workflow during program execution

– Model the actions the object will perform and in what order

– UML representation• Action state ( rectangle with its left and right sides replaced

by arcs curving outwards)

• Action order ( arrow with a stick arrowhead)

• Initial state (solid circle)

• Final state (solid circle enclosed in an open circle)

Page 61: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

61

Fig. 5.30 | Activity diagram for a BalanceInquiry object.

Page 62: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

62

Fig. 5.31 | Activity diagram for a withdrawal transaction.

Page 63: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

63

Fig. 5.32 | Activity diagram for a deposit transaction.

Page 64: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

64

6.14 (Optional) Identifying Class Operations

• Identifying operations– Examine key verbs and verb phrases in the requirements

document

• Modeling operations in UML– Each operation is given an operation name, a parameter

list and a return type:• operationName( parameter1, parameter2, …, parameterN ) : return type

• Each parameter has a parameter name and a parameter type

– parameterName : parameterType

Chapter 6

Page 65: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

65

6.14 (Optional) Identifying Class Operations (Cont.)

– Some operations may not have return types yet• Remaining return types will be added as design and

implementation proceed

• Identifying and modeling operation parameters– Examine what data the operation requires to perform its

assigned task

– Additional parameters may be added later on

Page 66: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

66

Fig. 6.20 | Verbs and verb phrases for each class in the ATM system.

Class Verbs and verb phrases

ATM executes financial transactions BalanceInquiry [none in the requirements document] Withdrawal [none in the requirements document] Deposit [none in the requirements document] BankDatabase authenticates a user, retrieves an account balance, credits a deposit

amount to an account, debits a withdrawal amount from an account Account retrieves an account balance, credits a deposit amount to an account,

debits a withdrawal amount from an account Screen displays a message to the user Keypad receives numeric input from the user CashDispenser dispenses cash, indicates whether it contains enough cash to satisfy a

withdrawal request DepositSlot receives a deposit envelope

Page 67: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

67

Fig. 6.21 | Classes in the ATM system with attributes and operations.

Page 68: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

68

Fig. 6.22 | Class BankDatabase with operation parameters.

Page 69: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

69

Fig. 6.23 | Class Account with operation parameters.

Page 70: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

70

Fig. 6.24 | Class Screen with operation parameters.

Page 71: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

71

Fig. 6.25 | Class CashDispenser with operation parameters.

Page 72: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

72

7.14 (Optional) Software Engineering Case Study (Cont.)

• Interaction Diagrams– Used to model interactions in the UML

– Communication diagrams• Also called collaboration diagrams

• Emphasize which objects participate in collaborations

– Sequence diagrams• Emphasize when messages are sent between objects

Chapter 7

Page 73: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

73

7.14 (Optional) Software Engineering Case Study (Cont.)

• Communication diagrams– Objects

• Modeled as rectangles

• Contain names in the form objectName : className

– Objects are connected with solid lines

– Messages are passed alone these lines in the direction shown by arrows

– Name of message appears next to the arrow

Page 74: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

74

Fig. 7.26 | Communication diagram of the ATM executing a balance inquiry.

Page 75: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

75

7.14 (Optional) Software Engineering Case Study (Cont.)

• Sequence of messages in a communication diagram

– Appear to the left of a message name

– Indicate the order in which the message is passed

– Process in numerical order from least to greatest

Page 76: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

76

Fig. 7.27 | Communication diagram for executing a balance inquiry.

Page 77: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

77

7.14 (Optional) Software Engineering Case Study (Cont.)

• Sequence diagrams– Help model the timing of collaborations

– Lifeline• Dotted line extending down from an object’s rectangle

– Represents the progression of time

– Activation• Thin vertical rectangle

– Indicates that an object is executing

Page 78: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

78

Fig. 7.28 | Sequence diagram that models a Withdrawal executing.

Page 79: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

79

Fig. 7.29 | Sequence diagram that models a Deposit executing.

Page 80: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

80

8.19  Starting to Program the Classes of the ATM System

• Visibility– Attributes normally should be private, methods invoked by

clients should be public

– Visibility markers in UML• A plus sign (+) indicates public visibility

• A minus sign (-) indicates private visibility

• Navigability– Navigability arrows indicate in which direction an

association can be traversed

– Bidirectional navigability• Associations with navigability arrows at both ends or no

navigability arrows at all can be traversed in either direction

Chapter 8

Page 81: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

81

8.19  Starting to Program the Classes of the ATM System (Cont.)

• Implementing the ATM system from its UML design (for each class)

– Declare a public class with the name in the first compartment and an empty no-argument constructor

– Declare instance variables based on attributes in the second compartment

– Declare references to other objects based on associations described in the class diagram

– Declare the shells of the methods based on the operations in the third compartment

• Use the return type void if no return type has been specified

Page 82: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

82

Fig. 8.24 | Class diagram with visibility markers.

Page 83: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

83

Fig. 8.25 | Class diagram with navigability arrows.

Page 84: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

84

Outline

1 // Class Withdrawal represents an ATM withdrawal transaction

2 public class Withdrawal

3 {

4 // no-argument constructor

5 public Withdrawal()

6 {

7 } // end no-argument Withdrawal constructor

8 } // end class Withdrawal

withdrawal.java

Class for Withdrawal

Empty no-argument constructor

Page 85: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

85

Outline

1 // Class Withdrawal represents an ATM withdrawal transaction

2 public class Withdrawal

3 {

4 // attributes

5 private int accountNumber; // account to withdraw funds from

6 private double amount; // amount to withdraw

7

8 // no-argument constructor

9 public Withdrawal()

10 {

11 } // end no-argument Withdrawal constructor

12 } // end class Withdrawal

withdrawal.java

Declare instance variables

Page 86: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

86

Outline

1 // Class Withdrawal represents an ATM withdrawal transaction

2 public class Withdrawal

3 {

4 // attributes

5 private int accountNumber; // account to withdraw funds from

6 private double amount; // amount to withdraw

7

8 // references to associated objects

9 private Screen screen; // ATM’s screen

10 private Keypad keypad; // ATM’s keypad

11 private CashDispenser cashDispenser; // ATM’s cash dispenser

12 private BankDatabase bankDatabase; // account info database

13

14 // no-argument constructor

15 public Withdrawal()

16 {

17 } // end no-argument Withdrawal constructor

18 } // end class Withdrawal

withdrawal.java

Declare references to other objects

Page 87: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

87

Outline

1 // Class Withdrawal represents an ATM withdrawal transaction

2 public class Withdrawal

3 {

4 // attributes

5 private int accountNumber; // account to withdraw funds from

6 private double amount; // amount to withdraw

7

8 // references to associated objects

9 private Screen screen; // ATM’s screen

10 private Keypad keypad; // ATM’s keypad

11 private CashDispenser cashDispenser; // ATM’s cash dispenser

12 private BankDatabase bankDatabase; // account info database

13

14 // no-argument constructor

15 public Withdrawal()

16 {

17 } // end no-argument Withdrawal constructor

18

19 // operations

20 public void execute()

21 {

22 } // end method execute

23 } // end class Withdrawal

withdrawal.java

Declare shell of a method with return type void

Page 88: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

88

Outline

1 // Class Keypad represents an ATM’s keypad

2 public class Keypad

3 {

4 // no attributes have been specified yet

5

6 // no-argument constructor

7 public Keypad()

8 {

9 } // end no-argument Keypad constructor

10

11 // operations

12 public int getInput()

13 {

14 } // end method getInput

15 } // end class Keypad

withdrawal.java

Page 89: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

89

Fig. 10.19 | Attributes and operations of classes BalanceInquiry, Withdrawal and Deposit.

Chapter 10

Page 90: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

90

10.9 (Optional) Software Engineering Case Study: Incorporating Inheritance into the ATM System

• UML model for inheritance– The generalization relationship

• The superclass is a generalization of the subclasses

• The subclasses are specializations of the superclass

•Transaction superclass– Contains the methods and fields BalanceInquiry, Withdrawal and Deposit have in common• execute method• accountNumber field

Page 91: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

91

Fig. 10. 20 | Class diagram modeling generalization of superclass Transaction and subclasses BalanceInquiry, Withdrawal and Deposit. Note that abstract class names (e.g., Transaction) and

method names (e.g., execute in class Transaction) appear in italics.

Page 92: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

92

Fig. 10.21 | Class diagram of the ATM system (incorporating inheritance). Note that abstract class names (e.g., Transaction)

appear in italics.

Page 93: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

93

Software Engineering Observation 10.12

A complete class diagram shows all the associations among classes and all the attributes and operations for each class. When the number of class attributes, methods and associations is substantial (as in Fig. 10.21 and Fig. 10.22), a good practice that promotes readability is to divide this information between two class diagrams—one focusing on associations and the other on attributes and methods.

Page 94: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

94

10.9 (Optional) Software Engineering Case Study: Incorporating Inheritance into the ATM System (Cont.)

• Incorporating inheritance into the ATM system design

– If class A is a generalization of class B, then class B extends class A

– If class A is an abstract class and class B is a subclass of class A, then class B must implement the abstract methods of class A if class B is to be a concrete class

Page 95: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

95

Fig. 10.22 | Class diagram with attributes and operations (incorporating inheritance). Note that abstract class names (e.g., Transaction) and method

names (e.g., execute in class Transaction) appear in italic

Page 96: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

96

Outline

Withdrawal.java

1 // Class Withdrawal represents an ATM withdrawal transaction

2 public class Withdrawal extends Transaction

3 {

4 } // end class Withdrawal

Subclass Withdrawal extends

superclass Transaction

Page 97: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

97

Outline

Withdrawal.java

1 // Withdrawal.java

2 // Generated using the class diagrams in Fig. 10.21 and Fig. 10.22

3 public class Withdrawal extends Transaction

4 {

5 // attributes

6 private double amount; // amount to withdraw

7 private Keypad keypad; // reference to keypad

8 private CashDispenser cashDispenser; // reference to cash dispenser

9

10 // no-argument constructor

11 public Withdrawal()

12 {

13 } // end no-argument Withdrawal constructor

14

15 // method overriding execute

16 public void execute()

17 {

18 } // end method execute

19 } // end class Withdrawal

Subclass Withdrawal extends superclass Transaction

Page 98: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

98

Software Engineering Observation 10.13

Several UML modeling tools convert UML-based designs into Java code and can speed the implementation process considerably. For more information on these tools, refer to the Internet and Web Resources listed at the end of Section 2.9.

Page 99: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

99

Outline

Transaction.java

(1 of 2)

1 // Abstract class Transaction represents an ATM transaction

2 public abstract class Transaction

3 {

4 // attributes

5 private int accountNumber; // indicates account involved

6 private Screen screen; // ATM’s screen

7 private BankDatabase bankDatabase; // account info database

8

9 // no-argument constructor invoked by subclasses using super()

10 public Transaction()

11 {

12 } // end no-argument Transaction constructor

13

14 // return account number

15 public int getAccountNumber()

16 {

17 } // end method getAccountNumber 18

Declare abstract superclass Transaction

Page 100: ATM Case Study Chapter 1-10 Optional Sections Java How To Program 7 th Ed.

1992-2007 Pearson Education, Inc. All rights reserved.

100

Outline

Transaction.java

(2 of 2)

19 // return reference to screen

20 public Screen getScreen()

21 {

22 } // end method getScreen

23

24 // return reference to bank database

25 public BankDatabase getBankDatabase()

26 {

27 } // end method getBankDatabase

28

29 // abstract method overridden by subclasses

30 public abstract void execute();

31 } // end class Transaction

Declare abstract method execute