/bankerl

A bank database simulation.

Primary LanguageErlang

bankerl

A bank database simulation. A homework assignment from my [concurrent software class] 1. (Project writeup does NOT belong to me, and this README is heavily based on the writeup.)

The Data

Bank

A list of 0 or more Accounts.

Account

A tuple of three elements:

  1. The account owner, an atom
  2. The account type (e.g. checking), an atom
  3. The account balance, a non-negative integer

The Functions

Return Types (Responses)

Each function returns a tuple of one of the following three forms.

  • {ok, Bank} for operations which initialize a new bank, i.e. init/0.
  • {ok} for operations that change the information in the Bank.
  • {ok, Response} for functions that query a Bank - in these cases, the new and old bank lists are the same. The type of the Response depends on the query itself.
  • {error, Diagnostic} for functions that fail; in such cases, it assumed the Bank is unchanged, and Diagnostic is a string describing the error.

Query Functions

  • bank:size(Bank) Returns the number of accounts in the Bank: {ok, Number}.
  • bank:accounts(Bank, Owner) Returns {ok, TypeList} where TypeList is the list of account types associated with Owner.
  • bank:balance(Bank, Owner, Type)
    • If the Owner has an account of the given Type, returns {ok, Balance}.
    • If not, returns {error, "No such account"}.

Operations

  • bank:open(Bank, Owner, Type)
    • If the Owner does not already have an account of the given Type in the Bank, returns {ok} and opens a new account with balance 0.
    • If the Owner does already have an account of the given Type, returns {error, "Duplicate account"}.
  • bank:close(Bank, Owner, Type)
    • If the Owner has an account of the given Type in the Bank, returns {ok, ClosingBalance} where ClosingBalance is the balance in the account; the account specified is now removed.
    • If not, returns {error, "No such account"}.
  • bank:deposit(Bank, Owner, Type, Amount)
    • If the Owner has an account of the given Type in the Bank, and if the Amount is positive, returns {ok}; the account balance is increased by Amount.
    • If the Amount is not positive, returns {error, "Negative amount"}.
    • If the Owner does not have an account of the given Type, returns {error, "No such account"}.
  • bank:withdraw(Bank, Owner, Type, Amount)
    • If the Owner has an account of the given Type in the Bank, and if the Amount is positive and does not exceed the account balance, returns {ok}; the account balance is decreased by Amount.
    • If the Amount is not positive, returns {error, "Negative amount"}.
    • If the Owner does not have an account of the given Type, returns {error, "No such account"}.
    • If the Amount exceeds the account balance, returns {error, "Overdrawn"}.