Created
January 10, 2015 13:16
-
-
Save javaeeeee/1b7a5327bdc25d06f0dd to your computer and use it in GitHub Desktop.
Withdraw method of an ATM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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