Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

OTExample ATM/Core

< OTExample ATM
Revision as of 08:08, 24 February 2010 by Stephan.cs.tu-berlin.de (Talk | contribs) (New page: ===Core classes of the ATM example=== ====Class Bank==== <source lang="java"> * * This class represents a very simple bank, only characterized by its name. *: public class Bank { ...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Core classes of the ATM example

Class Bank

/**
 * This class represents a very simple bank, only characterized by its name.
 *
 */
public class Bank {
    private String name;
 
    public Bank(String _name) {
        name = _name;
    }
 
    public String getName() {
        return name;
    }
 
}

Class Account

/**
 * This class represents an account.
 * In this application it is the base class of the ATM.ForeignAccount role
 * and the SpecialConditions.BonusAccount role.
 */
public class Account {
 
    private int balance;
    private Bank bank;
 
    /**
     * Constructor of an account object. Gets the owning bank as parameter.
     */
    public Account(Bank _bank) {
        bank = _bank;
    }
 
    /**
     * Get the balance of the account.
     */
    public int getBalance() {
        return balance;
    }
 
    /**
     * Get the bank of the account.
     */
    public Bank getBank() {
        return bank;
    }
 
    /**
     * Debit an amount from the account.
     */
    public boolean debit(int amount) {
 
        if (!(amount>balance)) {
            balance -= amount;
            return true;
        }
        return false;
    }
 
    /**
     * Credit an amount to the account.
     */
    public void credit(int amount) {
        balance += amount;
    }
}

Class AccessDeniedException

/**
 * This exception is thrown if an unauthorized access to an account is tried.
 */
public class AccessDeniedException extends Throwable {
 
}

as mentioned: nothing really surprising here.

Back to the top