UNB/ CS/ David Bremner/ teaching/ cs1083/ java/ BankAccount.java
public class BankAccount
{
    private long balance;

    public BankAccount()
    {
        balance = 0;
    }

    public BankAccount(long initialBalance)
    {
        balance = initialBalance;
    }

    public void deposit(long amount)
    {
        balance = balance + amount;
    }

    public void withdraw(long amount)
    {
        balance = balance - amount;
    }

    public long getBalance()
    {
        return balance;
    }

    public void transfer(BankAccount other, long amount)
    {
        withdraw(amount);
        other.deposit(amount);
    }
    public static void main(String[] args)
    {
        BankAccount account = new BankAccount(10000);

        final double INTEREST_RATE = 5;

        long interest;

        // compute and add interest for one period

        interest = (long)(account.getBalance() * INTEREST_RATE / 100);
        account.deposit(interest);

        System.out.println("Balance after year 1 is ¢"
                           + account.getBalance());

        // add interest again

        interest = (long)(account.getBalance() * INTEREST_RATE / 100);
        account.deposit(interest);

        System.out.println("Balance after year 2 is ¢"
                           + account.getBalance());
   }
}