title: C# How to test this code? BankAccount Class
body: <p>I'm fairly new to C# and was wondering how I can test this sample code. In other words, what do I put in my main (Program.cs) file in order to test the code in the Account.cs (base class) and SavingsAccount.cs (derived class)? I want to pass numbers and have the program output the ToString which is in the Account.cs and SavingsAccount.cs files if that makes sense.</p>
  
  <p><strong>Account.cs File:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace TestCode
  {
  public class Account
  {
  
          protected double interestRate;
          protected string owner;
          protected decimal balance;
  
          public Account(string o, decimal b, double ir)
          {
              this.interestRate = ir;
              this.owner = o;
              this.balance = b;
          }
  
          public Account(string o, double ir) :
            this(o, 0.0M, ir)
          {
          }
  
          public virtual decimal Balance
          {
              get { return balance; }
          }
  
          public virtual void Withdraw(decimal amount)
          {
              balance -= amount;
          }
  
          public virtual void Deposit(decimal amount)
          {
              balance += amount;
          }
  
          public virtual void AddInterests()
          {
              balance += balance * (Decimal)interestRate;
          }
  
          public override string ToString()
          {
              return owner + "'s account holds " +
                    +balance + " kroner";
          }
      }
  }
  </code></pre>
  
  <p><strong>SavingsAccount.cs File:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace TestCode
  {
   public class SavingsAccount : Account
      {
  
          public SavingsAccount(string o, double ir) :
            base(o, 0.0M, ir)
          {
          }
  
          public SavingsAccount(string o, decimal b, double ir) :
            base(o, b, ir)
          {
          }
  
          public override void Withdraw(decimal amount)
          {
              if (amount &lt; balance)
                  balance -= amount;
              else
                  throw new Exception("Cannot withdraw");
          }
  
          public override void AddInterests()
          {
              balance = balance + balance * (decimal)interestRate
                                - 100.0M;
          }
  
          public override string ToString()
          {
              return owner + "'s savings account holds " +
                    +balance + " kroner";
          }
      }
  }
  </code></pre>
  
  <p><strong>Program.cs File (What do I write here?):</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace TestCode
  {
  class Program
  {
      static void Main(string[] args)
      {
       SavingsAccount savingsaccount = new SavingsAccount("John", 0.0M, 0.70);
       savingsaccount.ToString();
      }
  }
  }
  </code></pre>
  
  <p>Thanks for any help!</p>