Atm Case Study

Only available on StudyMode
  • Topic: Madrid Metro, Class diagram, Subroutine
  • Pages : 46 (7238 words )
  • Download(s) : 67
  • Published : April 13, 2013
Open Document
Text Preview
J
ATM Case Study Code
J.1 ATM Case Study Implementation

This appendix contains the complete working implementation of the ATM system that we designed in the “Software Engineering Case Study” sections found at the ends of Chapters 1–8 and 10. The implementation comprises 670 lines of Java code. We consider the classes in the order in which we identified them in Section 3.10: •

ATM



Screen



Keypad



CashDispenser



DepositSlot



Account



BankDatabase



Transaction



BalanceInquiry



Withdrawal



Deposit

We apply the guidelines discussed in Section 8.19 and Section 10.9 to code these classes based on how we modeled them in the UML class diagrams of Fig. 10.21 and Fig. 10.22. To develop the bodies of class methods, we refer to the activity diagrams presented in Section 5.11 and the communication and sequence diagrams presented in Section 7.14. Note that our ATM design does not specify all the program logic and may not specify all the attributes and operations required to complete the ATM implementation. This is a normal part of the object-oriented design process. As we implement the system, we com-

J.2 Class ATM

1465

plete the program logic and add attributes and behaviors as necessary to construct the ATM system specified by the requirements document in Section 2.9. We conclude the discussion by presenting a Java application (ATMCaseStudy) that starts the ATM and puts the other classes in the system in use. Recall that we are developing a first version of the ATM system that runs on a personal computer and uses the computer’s keyboard and monitor to approximate the ATM’s keypad and screen. We also only simulate the actions of the ATM’s cash dispenser and deposit slot. We attempt to implement the system, however, so that real hardware versions of these devices could be integrated without significant changes in the code.

J.2 Class ATM

Class ATM (Fig. J.1) represents the ATM as a whole. Lines 6–12 implement the class’s attributes. We determine all but one of these attributes from the UML class diagrams of Fig. 10.21 and Fig. 10.22. Note that we implement the UML Boolean attribute userAuthenticated in Fig. 10.22 as a boolean attribute in Java (line 6). Line 7 declares an attribute not found in our UML design—an int attribute currentAccountNumber that keeps track of the account number of the current authenticated user. We will soon see how the class uses this attribute. Lines 8–12 declare reference-type attributes corresponding to the ATM class’s associations modeled in the class diagram of Fig. 10.21. These attributes allow the ATM to access its parts (i.e., its Screen, Keypad, CashDispenser and DepositSlot) and interact with the bank’s account information database (i.e., a BankDatabase object).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

// ATM.java
// Represents an automated teller machine
public class ATM
{
private boolean userAuthenticated; // whether user is authenticated private int currentAccountNumber; // current user's account number private Screen screen; // ATM's screen
private Keypad keypad; // ATM's keypad
private CashDispenser cashDispenser; // ATM's cash dispenser private DepositSlot depositSlot; // ATM's deposit slot
private BankDatabase bankDatabase; // account information database // constants corresponding to main menu options
private static final int BALANCE_INQUIRY = 1;
private static final int WITHDRAWAL = 2;
private static final int DEPOSIT = 3;
private static final int EXIT = 4;
// no-argument ATM constructor initializes instance variables public ATM()
{
userAuthenticated = false; // user is not authenticated to start currentAccountNumber = 0; // no current account number to start screen = new Screen(); // create screen

Fig. J.1 | Class ATM represents the ATM. (Part 1 of 4.)

1466
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42...
tracking img