Example #1
0
// perform transaction; overrides Transaction's pure virtual function
void Withdrawal::execute()
{
	bool cashDispensed = false; // cash was not dispensed yet
	bool transactionCanceled = false; // transaction was not canceled yet
	
	// get references to bank database and screen
	BankDatabase &bankDatabase = getBankDatabase();
	Screen &screen = getScreen();
	
	// loop until cash is dispensed or the user cancels
	do
	{
		// obtain the chosen withdrawal amount from the user
		int selection = displayMenuOfAmounts();
		// check whether user chose a withdrawal amount or canceled
		if ( selection != CANCELED )
		{ 
			amount = selection; // set amount to the selected dollar amount

			// get available balance of account involved
			double availableBalance = 45 bankDatabase.getAvailableBalance( getAccountNumber() );
			
			// check whether the user has enough money in the account
			if ( amount <= availableBalance )
			{
				// check whether the cash dispenser has enough money
				if ( cashDispenser.isSufficientCashAvailable( amount ) )
				{
					// update the account involved to reflect withdrawal
					bankDatabase.debit( getAccountNumber(), amount );
					cashDispenser.dispenseCash( amount ); // dispense cash
					cashDispensed = true; // cash was dispensed
					
					// instruct user to take cash
					screen.displayMessageLine( "\nPlease take your cash from the cash dispenser." );
				} // end if
				else // cash dispenser does not have enough cash
					screen.displayMessageLine( "\nInsufficient cash available in the ATM."
											   "\n\nPlease choose a smaller amount." );
			} // end if
			else // not enough money available in user's account
			{
				screen.displayMessageLine( "\nInsufficient funds in your account."
										   "\n\nPlease choose a smaller amount." );
			} // end else
		} // end if
		else // user chose cancel menu option
		{
			screen.displayMessageLine( "\nCanceling transaction..." );
			transactionCanceled = true; // user canceled the transaction
		} // end else
	} while ( !cashDispensed && !transactionCanceled ); // end do...while
} // end function execute
Example #2
0
// performs transaction; overrides Transaction's pure virtual function 
void Deposit::execute()
{
   BankDatabase &bankDatabase = getBankDatabase(); // get reference
   Screen &screen = getScreen(); // get reference

   amount = promptForDepositAmount(); // get deposit amount from user

   // check whether user entered a deposit amount or canceled
   if ( amount != CANCELED )
   {
      // request deposit envelope containing specified amount
      screen.displayMessage( 
         "\nPlease insert a deposit envelope containing " );
      screen.displayDollarAmount( amount );
      screen.displayMessageLine( " in the deposit slot." );

      // receive deposit envelope
      bool envelopeReceived = depositSlot.isEnvelopeReceived();

      // check whether deposit envelope was received
      if ( envelopeReceived )
      {  
         screen.displayMessageLine( "\nYour envelope has been received."
            "\nNOTE: The money deposited will not be available until we"
            "\nverify the amount of any enclosed cash, and any enclosed "
            "checks clear." );
         
         // credit account to reflect the deposit
         bankDatabase.credit( getAccountNumber(), amount ); 
      } // end if
      else // deposit envelope not received
      {
         screen.displayMessageLine( "\nYou did not insert an "
            "envelope, so the ATM has canceled your transaction." );
      } // end else
   } // end if 
   else // user canceled instead of entering amount
   {
      screen.displayMessageLine( "\nCanceling transaction..." );
   } // end else
} // end function execute