ATM Simulation Code

When this example was first developed (in 1996), the implementation was done in C++, using the curses package to produce a screen display that looks something like the machine being modelled. More recently (1997), it has been re-implemented using Java, with a full GUI interface. As noted in the initial page, minor changes were made to the overall design at that time as well. Both implementations are based on the same design, and except for the classes that model the components of the ATM, the code in both is very similar - in fact, much of the Java code is a straight translation of the corresponding C++ code. The following are the significant structural differences (see also the discussion of data type/prototype issues on the Operation Description Forms page):

  1. The Java constructor for class ATM has an additional parameter - a GUI container - that is not documented in the Class/Operation description forms. It uses this container to hold and display the various component parts of the ATM that it constructs.
  2. The C++ implementation of the machine components in atmparts.cc uses quite a number of static variables plus an additional module (window.h/.cc) to simulate the machine on the screen using the curses pacakge. Most of the classes in the Java atmparts package have additional fields and methods needed to support the GUI that are not documented on the Class/Operation description form pages. and there are two additional classes in package (GUILayout, QuestionDialog) that contribute to the task as well.
  3. The class Money has a different implementation in the two languages. In the C++ version, the operators +, -, +=, -=, ==, and < are overloaded for Money. Since operator overloading is not possible in Java, the Java version has methods named add (two versions), subtract (two versions), equals, and less. Also, the Java version has a set() method; in several places Money values are returned through the parameters of a method, which is done by assigning to a reference parameter in C++ and by setting the value of the object passed in Java.

Both implementations make use of two classes in addition to those that were developed during the early stages of the design. The need for these became evident when doing the detailed design of the individual classes. The class Money uses a class to implement money as an abstract data type. The class Status encapsulates status codes that indicate success or failure of various transactions. (This is basically an enum in C++, and a class that consists of static final int's in Java.)

C++ Implementation
Java Implementation

[ Intro ] [ Requirements ] [ Domain Objects ] [ Use Cases ] [ State Diagram ] [ Interaction Diagram ]
[ CRC Cards ] [ Class Diagram ] [ Class Desc. Forms ] [ Operation Desc. Forms ] [ Code ] [ Executable ]

Copyright © 1996, 1997, 1998 - Russell C. Bjork. Permission for non-commercial reproduction for educational use is hereby granted; all other rights are reserved.

C++ Implementation

The implementation of the ATM simulation in C++ consists of eight modules that declare and implement the various classes - most consisting of an interface (.h) file that contains the class declaration(s) and an implementation (.cc) file that implements the methods declared in the interface. (No implementation file is needed for the class Status, and no interface file is needed for the main program.) Most modules implement a single class, but all the component parts of the ATM are grouped together into a single atmparts module, and all types of transactions are grouped into a single transactions module.

The current version of these files has been compiled and run on both a VAX/VMS system and a Linux system, both using gnu C++. A complete downloadable package of the all the source code will eventually be available via anonymous ftp. The README file in that package contains information about system specific details.

Files that Implement the Various Classes, Plus Main Program

InterfaceImplementation Purpose
atm.h atm.ccATM itself
atmparts.h atmparts.cc Component parts of ATM
session.h session.ccPerform a customer session
transaction.h transaction.ccPerform a transaction
bank.h bank.cc Manage communication with bank
money.h money.cc Abstract data type Money
status.h(None) Status code values
(None)main.ccMain program

NOTE: The implementation file atmparts.cc contains very system-specific code for displaying some likeness of an ATM. Frankly, some of it is pretty ugly! This file also utilizes a windows module (windows.h/.cc) which builds a window class on top of the curses package. Likewise, the implementation of class Bank is very simple and also fairly ugly - i.e. card numbers and PINs are hardwired in, etc. It is intended that a more realistic implementation be left as an exercise to the student. For these reason, no links to these files are included above (though they will be included in the complete downloadable package.) Also, all of the implementation files include a file sysdep.h that incorporates system-dependent declarations. If you really _have_ to see these files, here are the links - but don't say I didn't warn you :-) ! atmparts.cc bank.cc window.h window.cc sysdep.h

Java Implementation

The implementation of the ATM simulation in Java allows the simulation to be run either as a stand-alone application, or as an applet. It has the following package structure:

In keeping with standard Java practice, each class is implemented as a separate source file - except that the subclasses of Transaction are implemented in the same source file as class Transaction, since no class outside of Transaction needs explicit awareness of the individual subclasses. Of course, there is only one source file for each class - no separate interface and implementation as in C++. However, the standard java development tools include a program javadoc which creates an html document that describes the interface to a class by extracting the needed information from the source file. This has been created for all classes except the two main program classes. The links below allow access both to the javadoc-created interface documentation and to the actual source for each class. You can also view the complete javadoc documentation.

Please note that, at the time this example was created, the current version of Java was JDK 1.0.2, and the code below is based on the 1.0.2 API. When JDK 1.1 came out, I needed to change one class in order to get it to run under 1.1 browsers - note that there are links to two versions of the applet on the Executables page. Though a JDK 1.1 or later compiler will complain about using deprecated API features, the code with the one changed class will compile and run. At some point in the near future, I hope to update the code to the 1.1/1.2 API. For now, if you wish to compile the code yourself, be sure to get the correct version of class QuestionDialog (see below).

Files that Implement the Various Classes, Plus Main Program/Applet

DocumentationSource Purpose
class ATM ATM.java ATM itself
class Bank Bank.java Manage communication with bank
class Session Session.java Perform a customer session
package atm.atmparts CardReader.java
CashDispenser.java
Display.java
EnvelopeAcceptor.java
Keyboard.java
OperatorPanel.java
ReceiptPrinter.java
Component parts of ATM
package atm.transaction Transaction.java Perform a transaction
class Money Money.java
Abstract data type Money
class Status Status.java Status code values
(None) ATMMain.java Main program - application version
(None) ATMApplet.java Main program - applet version

NOTE: The implementation of class Bank is very simple and also fairly ugly - i.e. card numbers and PINs are hardwired in, etc. It is intended that a more realistic implementation be left as an exercise to the student. The atmparts package include two classes which are needed by the GUI, but are not otherwise documented in the design: class GUILayout and class QuestionDialog. For these reason, no links to these files are included above (though they will be included in the complete downloadable package.) If you really _have_ to see these files, here are the links - but don't say I didn't warn you :-)!
Bank.java
GUILayout.java
QuestionDialog.java (1.0.2 version)
QuestionDialog.java (1.1 version)