Java Reference
In-Depth Information
12.5.5 Implementation
Finally, the time has come to implement the ATM simulator. The implementation
phase is very straightforward and should take much less time than the design phase.
A good strategy for implementing the classes is to go Ȓbottom-upȓ. Start with the
classes that don't depend on others, such as Keypad and BankAccount . Then
implement a class such as Customer that depends only on the BankAccount
class. This Ȓbottom-upȓ approach allows you to test your classes individually. You
will find the implementations of these classes at the end of this section.
The most complex class is the ATM class. In order to implement the methods, you
need to define the necessary instance variables. From the class diagram, you can
tell that the ATM has a bank object. It becomes an instance variable of the class:
public class ATM
{
. . .
private Bank theBank;
}
563
564
From the description of the ATM states, it is clear that we require additional
instance variables to store the current state, customer, and bank account.
public class ATM
{
. . .
private int state;
private Customer currentCustomer;
private BankAccount currentAccount;
. . .
}
Most methods are very straightforward to implement. Consider the
selectCustomer method. From the design documentation, we have the
description
/**
Finds customer in bank.
If found sets state to ACCOUNT, else to START.
(Precondition: state is PIN)
Search WWH ::




Custom Search