//
/* * Example ATM simulation - file session.cc * * This file implements the class that represents a single customer session * with the ATM, declared in session.h * * Copyright (c) 1996 - Russell C. Bjork * */ #include "sysdep.h" #include "bank.h" #include "session.h" #include "transaction.h" #include "atm.h" //
Session::Session(int cardNumber)
: _state(RUNNING),
_cardNumber(cardNumber)
{ }
//
void Session::doSessionUseCase()
{
_PIN = theATM.getPIN();
do
{
_currentTransaction =
Transaction::makeTransaction(theATM.getTransactionChoice(), * this);
_currentTransaction -> doTransactionUseCase();
delete _currentTransaction;
}
while (_state == RUNNING && theATM.getDoAnotherTransactionChoice());
if (_state != ABORTED)
theATM.ejectCard();
}
//
Bank::ApprovalCode Session::doInvalidPINExtension()
{
Bank::ApprovalCode code;
for (int i = 0; i < 3; i ++)
{ _PIN = theATM.reEnterPIN();
code = _currentTransaction -> sendToBank();
if (code != Bank::INVALID_PIN)
return code;
}
theATM.retainCard();
_state = ABORTED;
}
//
int Session::cardNumber() const
{ return _cardNumber; }
//
int Session::PIN() const
{ return _PIN; }
//