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) {
      nextAccountNumber++;
      accounts.Add(this);                                    
      this.accountNumber = nextAccountNumber;
      this.interestRate = 0.0;
      this.owner = owner;                                    
      this.balance = 0.0M;
   }
   public BankAccount(string owner, double interestRate) {
      nextAccountNumber++;
      accounts.Add(this);
      this.accountNumber = nextAccountNumber;
      this.interestRate = interestRate;
      this.owner = owner; 
      this.balance = 0.0M;
   }   
   public decimal Balance () {
      return balance;
   }
   public static long NumberOfAccounts (){
     return nextAccountNumber;
   }
   public static BankAccount GetAccount (long accountNumber){
      foreach(BankAccount ba in accounts)
        if (ba.accountNumber == accountNumber)
           return ba;
      return null;
   }
   public void Withdraw (decimal amount) {
      balance -= amount;
   }
   public void Deposit (decimal amount) {
      balance += amount;
   }
   public void AddInterests() {
      balance = balance + balance * (decimal)interestRate;
   }    
   public override string ToString() {
      return owner + "'s account, no. " + accountNumber + " holds " +
            + balance + " kroner";
   }
}  |  |  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Adds the current object to accounts.
 
 
this.owner refers to the shadowed instance variable
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   |