using System;
using System.Collections;
public class BankAccount {
private double interestRate;
private string owner;
private decimal balance;
private long accountNumber;
private static long nextAccountNumber = 0;
private static ArrayList accounts = new ArrayList();
public BankAccount(string owner) {
BankAccount.nextAccountNumber++;
BankAccount.accounts.Add(this);
this.accountNumber = nextAccountNumber;
this.interestRate = 0.0;
this.owner = owner;
this.balance = 0.0M;
}
public BankAccount(string owner, double interestRate) {
BankAccount.nextAccountNumber++;
BankAccount.accounts.Add(this);
this.accountNumber = nextAccountNumber;
this.interestRate = interestRate;
this.owner = owner;
this.balance = 0.0M;
}
public decimal Balance () {
return this.balance;
}
public static long NumberOfAccounts (){
return BankAccount.nextAccountNumber;
}
public static BankAccount GetAccount (long accountNumber){
foreach(BankAccount ba in BankAccount.accounts)
if (ba.accountNumber == accountNumber)
return ba;
return null;
}
public void Withdraw (decimal amount) {
this.balance -= amount;
}
public void Deposit (decimal amount) {
this.balance += amount;
}
public void AddInterests() {
this.balance = this.balance + this.balance * (decimal)interestRate;
}
public override string ToString() {
return this.owner + "'s account, no. " + this.accountNumber + " holds " +
+ this.balance + " kroner";
}
} | |
this.balances emphasizes that we refer to the
balance of the current bank account object.
|