Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    The base class BankAccount.Lecture 15 - slide 10 : 13
Program 1
using System;

/// \mainpage Doxygen Demo.
/// \section intro_sec Introduction
/// This documentation serves as a Doxygen demonstration.
/// We document the BankAccount class and a number of 
/// specialized bank account classes.

/// <summary> 
///   A simple bank account created as an everyday example
///   for the OOP course. Used in particular for demonstrating inheritance.
/// </summary>
/// <example>
///   <code>
///      BankAccount ba = new BankAccount("Peter");
///      ba.Deposit(100.0);
///      ba.Withdraw(50.0);
///   </code>
/// </example>
public class BankAccount {

   protected double interestRate;
   protected string owner;
   protected decimal balance;

   /// <summary>
   ///  Construct a bank account from owner, balance, and interestRate. 
   /// </summary>
   /// <param name = "o"> The owners name </param>
   /// <param name = "b"> The initial amount of this account</param>
   /// <param name = "ir"> 
   ///    The interest rate. 
   ///    Annual interet is calculated as balance * interestRate 
   /// </param>
   public BankAccount(string o, decimal b, double ir) {
      this.interestRate = ir;
      this.owner = o; 
      this.balance = b;
   }

   /// <summary>
   ///  Construct a bank account from owner and interestRate. 
   /// </summary>
   /// <param name = "o"> The owners name </param>
   /// <param name = "ir"> 
   ///    The interest rate. 
   ///    Annual interet is calculated as balance * interestRate 
   /// </param>
   public BankAccount(string o, double ir):
     this(o, 0.0M, ir) {
   }

   /// <summary>
   ///   Returns the current amount of the bank account 
   ///  with affecting the account.
   /// </summary>
   ///  <value> The amount of money </value>
   public virtual decimal Balance {
     get {return balance;}
   }

   /// <summary>
   /// <list>
   ///   <item> Withdraw an amount of money from the account. </item>
   ///   <item> This decreases the balance of the account. </item>
   /// <list>
   /// </summary>
   /// <param name = "amount"> 
   ///  The amount of money to withdraw from the account.
   ///  Precondition: Must be non-negative.
   /// </param>   
   public virtual void Withdraw (decimal amount) {
      balance -= amount;
   }

   /// <summary>
   ///   Withdraw an amount of money from the account.
   ///   This increases the balance of the account.
   /// </summary>
   /// <param name = "amount"> 
   ///  The amount of money to deposit to the account.
   ///  Precondition: Must be non-negative.
   /// </param>   
   public virtual void Deposit (decimal amount) {
      balance += amount;
   }
 
   /// <summary>
   ///  Add the annual interest to the account.
   ///  This may increase the current balance of the account.
   /// </summary>
   public virtual void AddInterests() {
      balance += balance * (Decimal)interestRate;
   }    

   /// <summary>
   ///   Return a text string that represents this account
   ///   for output purposes
   /// </summary>
   public override string ToString() {
      return owner + "'s account holds " +
            + balance + " kroner";
   }
}