Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

BankTellerRole

Matthew Pohlmann edited this page Jan 1, 2014 · 1 revision

####Description Role inside of the bank that is responsible for opening accounts, withdrawing money (requested by customer), depositing money (given by customer), and granting loans.

####Class Signature

public class BankTellerRole extends Role implements BankTeller {}

####Data

MyCustomer currentCustomer;
TellerState state;
public enum CustomerAction { OpenAccount, WithdrawMoney, DepositMoney, TakeOutLoan }
private class MyCustomer {
    BankCustomerRole currentCustomer;
    CustomerAction action;
    int accountNumber;
    double availableBalance;
    double transactionAmount;
}
public enum TellerState {
    Unoccupied,
    OpeningAccount,
    WithdrawingMoney,
    DepositingMoney,
    AssessingLoan
}

####Scheduler

if currentCustomer.state == OpenAccount then,
    openAccount();
if currentCustomer.state == WithdrawMoney then,
    withdrawMoney();
if currentCustomer.state == DepositMoney then,
    depositMoney();
if currentCustomer.state == TakeOutLoan then,
    assessLoan();

####Messages

public void msgOpenAccount(BankCustomerRole cust, double startingBalance) {
    currentCustomer = new MyCustomer(cust, CustomerAction.OpenAccount, startingBalance);
    stateChanged();
}
public void msgDepositMoney(BankCustomerRole cust, int actNum, double amtToDeposit) {
    currentCustomer = new MyCustomer(cust, CustomerAction.DepositMoney, actNum, amtToDeposit);
    stateChanged();
}
public void msgWithdrawMoney(BankCustomerRole cust, int actNum, double amtToWithdraw) {
    currentCustomer = new MyCustomer(cust, CustomerAction.WithdrawMoney, actNum, amtToWithdraw);
    stateChanged();
}
public void msgRequestMoney(BankCustomerRole cust, int actNum, double amtRequested) {
    currentCustomer = new MyCustomer(cust, CustomerAction.TakeOutLoan, actNum, amtRequested);
    stateChanged();
}

####Actions

private void openAccount() {
    // Create an account number
    
    Bank.addAccount(actNum, currentCustomer.transactionAmount);
    currentCustomer.getCustomer.msgAccountIsOpened(actNum); 
    Bank.getGuard.msgDoneWithCustomer(this);
}
private void depositMoney() {
    Bank.addMoneyToAccount(currentCustomer.getAccountNum, currentCustomer.getTransactionAmount);
    
    myCustomer.getCustomer.msgMoneyIsDeposited(Bank.getAccountBalance(currentCustomer.getAccountNum)); 
    Bank.getGuard.msgDoneWithCustomer(this);
}
private void withdrawMoney() {
    if (Bank.getAccountBalance(currentCustomer.getAccountNum) > transationAmount) {
        Bank.subtractMoneyFromAccount(currentCustomer.getAccountNum, currentCustomer.getTransactionAmount);
        myCustomer.getCustomer.msgMoneyIsWithdrawn(Bank.getAccountBalance(currentCustomer.getAccountNum));
    }
    else { // Overdrawn account, give them remaining balance
        Bank.subtractMoneyFromAccount(currentCustomer.getAccountNum, Bank.getAccountBalance(currentCustomer.getAccountNum));
        myCustomer.getCustomer.msgOverdrawnAccount();
    }
    Bank.getGuard.msgDoneWithCustomer(this);
}
private void takeOutLoan() {
    if (Bank.getBankBalance > currentCustomer.getTransactionAmount) {
        myCustomer.getCustomer.msgLoanGranted();
    }
    else {
         myCustomer.getCustomer.msgLoanDenied();
    }
    Bank.getGuard.msgDoneWithCustomer(this);
}

Wiki Home | Design Home

Clone this wiki locally