Skip to content

Instantly share code, notes, and snippets.

@javaeeeee
Created January 10, 2015 13:16
Show Gist options
  • Save javaeeeee/1b7a5327bdc25d06f0dd to your computer and use it in GitHub Desktop.
Save javaeeeee/1b7a5327bdc25d06f0dd to your computer and use it in GitHub Desktop.
Withdraw method of an ATM
public void withdrawCash() throws BankServiceException {
//Show user options to withdraw cash
screen.displayMenuOfWithdrowalAmounts();
//Read amount from the keypad
BigDecimal amount = keypad.getAmount();
//Connect to the bank and check balance
BigDecimal balance = bankService.getBalance();
//Check if there is enough money on the account
if (isTransactionPossible(amount, balance)) {
//Check if there is enough cash in the dispenser
if (!cashDispenser.isThereEnoughMoney(amount)) {
//Display error message
screen.displayError(INSUFFICIENT_CASH_AVAILABLE);
} else {
//Debit amount from user's account
bankService.debit(amount);
//Dipenses cash
cashDispenser.dispenseCash(amount);
//Bids goodbye
screen.displayMessage(GOODBYE);
}
} else {
//Display error message
screen.displayError(AMOUNT_EXCEEDS_BALANCE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment