This repository was archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
BankCustomerRole
Matthew Pohlmann edited this page Jan 1, 2014
·
1 revision
####Description Role inside of the bank that is able to open an account, deposit money, withdraw money (if enough money is available in account), and take out a loan (if they meet the requirements for opening up a loan).
####Class Signature
public class BankCustomerRole extends Role implements BankCustomer {}####Data
BankTellerRole myTeller;
int accountNumber;
double accountBalance;
Intention intent;
CustomerState state = enteringBank;public enum CustomerState {
EnteringBank,
Waiting,
WalkingToTeller,
TalkingToTeller,
OpeningAccount,
WithdrawingMoney,
DepositingMoney,
TakingOutLoan
LeavingBank
};public enum Intention {
OpenAccount,
WithdrawMoney,
DepositMoney,
TakeOutLoan
};####Scheduler
if state == CustomerState.EnteringBank then,
addToWaitingList();if state == CustomerState.WalkingToTeller then,
goToTeller();if state == CustomerState.TalkingToTeller && (myPerson.getAccountNumber() == null || intent == Intention.OpenAccount) then,
openBankAccount();if state == CustomerState.TalkingToTeller && intent == Intention.WithdrawMoney then,
withdrawMoney();if state == CustomerState.TalkingToTeller && intent == Intention.DepositMoney then,
depositMoney();if state == CustomerState.TalkingToTeller && intent == Intention.TakeOutLoan then,
takeOutLoan();####Messages
public void msgSeeTeller(BankTellerRole teller) {
state = CustomerState.WalkingToTeller;
destination = teller.getLocation
}public void msgAccountIsOpened(int actNum) {
myPerson.setBankAccount(actNum);
}public void msgMoneyIsDeposited(int newBalance) {
accountBalance = newBalance;
}public void msgMoneyIsWithdrawn(int newBalance) {
accountBalance = newBalance;
}public void msgLoanIsGranted(int loanAmount) {
myPerson.setMoney(myPerson.getMoney() + loanAmount);
}public void msgLeaveBank() {
state = CustomerState.LeavingBank;
}####Actions
private void addToWaitingList() {
Bank.getGuard.msgHereToSeeTeller(this);
state = CustomerState.Waiting;
}private void goToTeller() {
DoGoToTeller(xDest, yDest);
state = CustomerState.TalkingToTeller;
}private void openBankAccount() {
myTeller.msgOpenAccount(this, startingBalance);
}private void withdrawMoney() {
myTeller.msgWithdrawMoney(accountNumber, amtNeeded);
}private void depositMoney() {
myTeller.msgDepositMoney(accountNumber, amtToDeposit);
}private void takeOutLoan() {
myTeller.msgRequestMoney(accountNumber, amtRequested);
}