Dr. Sridhar Nerur

 Home > Courses > Project

Syllabus

Schedule

Project

Examples

Presentations

INSY 4306 - ADVANCED SYSTEMS DESIGN

Fall 2002

Banking Application

 

ABC Bank allows customers to open Savings and Checking accounts. A customer may have more than one account. Checking accounts must have a minimum balance of $250.00. Customers may withdraw money from or deposit money into their accounts. The system to be built should keep track of the transactions for a given account. Each transaction should specify the type of transaction (deposit or withdrawal), type of account involved in the transaction (checking or savings), date of transaction, and beginning and ending balance of the account. At this time, only the teller or bank representative may access the system on behalf of the customer.

Draw:

1)   A Use Case Diagram for the description given above.

2)      A Class Diagram

3)      Sequence or Collaboration diagrams for the Withdraw and Deposit use cases

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Class Diagram for the Banking Application

 

 

 

 

 

 

 

 

 

 

 

 

 

Sequence Diagram for Withdraw from Account

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Collaboration Diagram

 

 

 

 

 

 

 

 

 

 

 

Statecharts Exercise

Assume that an account in the Banking Application has the following characteristics:

1.         An account is in the “Open” state when it is created

2.                  When the account balance falls below the minimum balance, it goes to the “Overdrawn” state, and the customer is notified immediately. Such an account would be restored to the “Open” state as soon as the balance goes above the minimum required.

3.                  Accounts that remain in the “Overdrawn” state for 30 days are automatically canceled, in which case the account goes to the “Canceled” state.

4.                  In addition, the customer may cancel an account, which would put the account in the “Canceled” state.

Draw a statechart to model the lifecycle of an account object.

 

 

 

 

 

 

 

Implementation Model – Sample code for the Banking Application

package account;

import java.util.*;

import javax.swing.*;

public class Account

{

    private static int numberOfAccounts;

    private int accountNumber;

    protected double balance;

    private static double minBalance;

    private Customer customer;

    private Vector transactions;

    static

    {

        numberOfAccounts = 0;

        minBalance = 250.00;

    }

    public Account(Customer c)

    {

        customer = c;

        accountNumber = ++numberOfAccounts;

        transactions = new Vector();

    }

    public void addTransaction(Transaction t)

    {

        transactions.add(t);

    }

    public String withdraw(double money)

    {

        if ( okToWithdraw(money) )

        {

        Transaction temp = new Transaction("Withdraw",

                    this.accountNumber);

        temp.setBeginningBalance(balance);

        balance -= money; //balance = balance - money;

        temp.setEndingBalance(balance);

        addTransaction(temp);

        }

        else

        JOptionPane.showMessageDialog(new JFrame(),"You must maintain" +

          " a minimum of $" + minBalance);

        return new Double(balance).toString();

    }

    public String deposit(double money)

    {

        Transaction temp = new Transaction("Deposit",

                accountNumber);

        temp.setBeginningBalance(balance);

        balance += money;

        temp.setEndingBalance(balance);

        addTransaction(temp);

        return new Double(balance).toString();

    }

 

    public void displayTransactions()

    {

        if ( transactions.size() == 0)

        System.out.println("No Transactions for " +

            "Account# " + accountNumber);

        else

            for(int i = 0; i < transactions.size();i++)

                System.out.println(transactions.get(i));

    }

    public boolean okToWithdraw(double money)

    {

        return ( balance - money >= minBalance );

    }

 

    public String toString()

    {

        return

             "\t\tACCOUNT INFORMATION\n\n" +

            "Account#:\t" + accountNumber +

            "\nBalance:\t" + balance;

    }

 

    public int getAccountNumber()

    {

        return accountNumber;

    }

 

 

   public String getBalance()

   {

      return new Double(balance).toString();

   }

 

}

 

 

 

package account;

import java.io.*;

import java.util.*;

public class Customer

{

 

//data for customer

private String name;

private String id;

private String address;

private Vector accounts;

 

    public Customer()

    {

    name = "Nobody";

    id = "007";

    address = "Utopia";

    accounts = new Vector();

    }

 

    public Customer(String name, String address,

                     String id)

    {

        this.name = name;

        this.address = address;

        this.id = id;

        accounts = new Vector();

    }

 

    public String toString()

    {

        String acctInfo = "";

        if ( accounts.size() == 0 )

        acctInfo = "Customer has no accounts\n";

        else //customer has accounts

            for(int i = 0; i < accounts.size();i++)

            {

              Account temp = (Account) accounts.get(i);

              acctInfo += temp.toString();

            }

        return "\t\tCUSTOMER INFORMATION\n" +

        "\n\nName:\t" + name + "\n" +

        "Address:\t" + address + "\n" +

        "Cust#:\t" + id + "\n" + acctInfo;

    }

 

    public void getDetails()

    {

        BufferedReader input = new BufferedReader

            (new InputStreamReader(System.in));

        try

        {

          System.out.println("Enter name: ");

          name = input.readLine();

          System.out.println("Enter SS#: ");

          id = input.readLine();

          System.out.println("Enter address: ");

          address = input.readLine();

        }

        catch (IOException i)

        {}

 

    }

 

 

    public int numberOfAccounts()

    {

    return accounts.size();

    }

 

 

    public String getID()

    {

        return id;

    }

 

    public void addAccount(Account anAccount)

    {

      accounts.add(anAccount);

    }

 

    public void getAccounts(String[] s)

    {

     for(int i = 0; i < accounts.size(); i++)

     {

      //s[i] = accounts.get(i).getAccountNumber().toString();

       Account temp = (Account) accounts.get(i);

       s[i] = new Integer(temp.getAccountNumber()).toString();

     }

    }

 

    public Account getAccount(int acctNum)

    {

        Account temp = null;

        int s;

        for(int i = 0; i < accounts.size(); i++)

        {

            temp = (Account) accounts.get(i);

            s = temp.getAccountNumber();

            if ( s == acctNum )

            return temp;

            else

            temp = null;

        }

 

        return temp;

    }

 

}

 

 

package account;

 

import java.io.*;

import java.util.*;

 

final public class AccountFacade

{

 

    private String line;

    private BufferedReader in = new BufferedReader

               (new InputStreamReader(System.in));

    Hashtable customers;

    Hashtable accounts;

    Account anAccount;

    private static AccountFacade af = new AccountFacade();

    private Customer customer;

 

    private AccountFacade()

    {

    customers = new Hashtable();

    accounts = new Hashtable();

    }

 

    public static AccountFacade getFacade()

    {

        return af;

    }

 

 

 

 

    public Customer addCustomer(Customer c)

    {

        customers.put(c.getID(), c);

        return c;

    }

 

    public Customer findCustomer(String line)

    {

 

        customer = (Customer)customers.get(line);

 

        return customer;

    }

 

    public Account findAccount(String line)

    {

       

        int j = 0;

        try

        {

        j = Integer.parseInt(line.trim());

        }

        catch (Exception e)

        {}

 

        return (Account)accounts.get(new Integer(j));

       

    }

 

    public void displayTransactions(String line)

    {

      anAccount = findAccount(line);

      if ( anAccount != null )

        anAccount.displayTransactions();

      else

        System.out.println("No such account");

    }

 

    public String withdraw(String line, double money)

    {

        anAccount = findAccount(line);

       

        return anAccount.withdraw(money);

       

    }

 

    public String deposit(String line, double money)

    {

        anAccount = findAccount(line);

        return anAccount.deposit(money);

      

    }

 

    public String displayCustomer(String custNumber)

    {

        customer = findCustomer(custNumber);

        if ( customer != null )

        return customer.toString();

        else

        return "";

    }

 

 

    public String createAccount(String custNumber)

    {

        customer = findCustomer(custNumber);

        if ( customer == null )

        {

            //temp = new Customer();

            //temp.getDetails();

            //customers.put(temp.getID(), temp);

CustomerDialog dialog = new CustomerDialog(new UserInterface(),                                        this);

            if ( !dialog.open() )

            return "";

            //addCustomer(temp);

 

        }

 

        anAccount = new Account(customer);

        int x = anAccount.getAccountNumber();

        accounts.put(new Integer(x), anAccount);

        customer.addAccount(anAccount);

        return new Integer(x).toString();

    }

 

}