title: Bank System Deposit/Withdraw
body: <p>I am new to C# and expecially to OOP and its principles. So I have a homework from my university to implement a "bank system". I have a deposit, mortgage and loan accounts, also customers, which should be Individual or Companies. I have a formulas for calculating the interest rate for every account but its not important at the moment because i think for the moments this is working fine. My problem is with Deposit function. Here you can see my hierarchy:</p>
  
  <p><strong>Account.cs</strong></p>
  
  <pre><code>public abstract class Account
  {
      private Customer customer;
      private double balance;
      private double interestRate;
  
      public Customer Customer { get; private set; }
      public double Balance { get; private set; }
      public double InterestRate { get; private set; }
  
      public Account(Customer customer, double balance, double interestRate)
      {
          this.Customer = customer;
          this.Balance = balance;
          this.InterestRate = interestRate;
      }
  
  
  
      public abstract double CalculateInterestAmount(int numberOfMonths);
      public virtual double Deposit(double amount)
      {
          return this.Balance + amount;
      }        
  }
  </code></pre>
  
  <p><strong>DepositAccount.cs</strong></p>
  
  <pre><code>public class DepositAccount : Account
  {
      public DepositAccount(Customer customer, double balance, double interestRate) : base(customer, balance, interestRate)
      { }
  
      public override double CalculateInterestAmount(int numberOfMonths)
      {
          double interest = 0.0;
          if (this.Balance &lt; 1000)
          {
              interest = 0.0;
          }
          else
          {
              interest = numberOfMonths * this.InterestRate;
          }
          return interest;
      }
      public double Withdraw(double amount)
      {
  
          double result = 0.0;
          if (amount &gt; this.Balance)
          {
              return result = 0.0;         
          }
  
          else
          {
              result = this.Balance - amount;
          }
  
  
          return result;
      }
  }
  </code></pre>
  
  <p><strong>LoanAccount.cs</strong></p>
  
  <pre><code>public class LoanAccount : Account
  {
  
      public LoanAccount(Customer customer, double balance, double interestRate) : base(customer, balance, interestRate) { }       
  
      public override double CalculateInterestAmount(int numberOfMonths)
      {
          double interest = 0.0;
  
          if (this.Customer is IndividualCustomer)
          {
              if (numberOfMonths &gt; 3)
              {
                  interest = (numberOfMonths - 3) * this.InterestRate;
              }
              else
              {
                  interest = 0.0;
              }
  
          }
  
          if (this.Customer is CompanyCustomer)
          {
              if (numberOfMonths &gt; 2)
              {
                  interest = (numberOfMonths - 2) * this.InterestRate;
              }
              else
              {
                  interest = 0.0;
              }
          }
  
          return interest;
      }
  }
  </code></pre>
  
  <p><strong>MortgageAccount.cs</strong></p>
  
  <pre><code>public class MortgageAccount : Account
  {
      public MortgageAccount(Customer customer, double balance, double interestRate) : base(customer, balance, interestRate)
      { }
  
  
      public override double CalculateInterestAmount(int numberOfMonths)
      {
          double interest = 0.0;
          if (this.Customer is CompanyCustomer)
          {
              if (numberOfMonths &lt;= 12)
              {
                  interest = (numberOfMonths * this.InterestRate) / 2;
              }
              else
              {
                  interest = (((12 * this.InterestRate) / 2) + ((numberOfMonths - 12) * this.InterestRate));
              }
          }
  
          if (this.Customer is IndividualCustomer)
          {
              if (numberOfMonths &lt;= 6)
              {
                  interest = 0.0;
              }
              else
              {
                  interest = (numberOfMonths - 6) * this.InterestRate;
              }
          }
  
          return interest;
      }
  }
  </code></pre>
  
  <p><strong>Main</strong></p>
  
  <pre><code>static void Main(string[] args)
      {
          //Customers
          Customer individual = new IndividualCustomer();
          Customer company = new CompanyCustomer();
  
          //Accounts
          Account mort = new MortgageAccount(individual, 2500.0, 0.2);     
          Account depo = new DepositAccount(individual, 400, 0.7);
          Account loan = new LoanAccount(company, 10000, 3.2);
  
          loan.Deposit(999); // this is not working. Balance should be 10999 but it is still 10000
          Console.WriteLine(loan.Balance);
          List&lt;Account&gt; accounts = new List&lt;Account&gt;();
          accounts.Add(mort);
          accounts.Add(depo);
          accounts.Add(loan);
          Bank b = new Bank(accounts);
          Console.WriteLine(b.ToString());
      }
  </code></pre>
  
  <p>The problem is when I add some amount to any account it returns the same as old. I mean when i debug it is really 10999 but I print 10000. Where is the problem? Also for the method Withdraw only DepositCccounts are allowed to withdraw and when i instantiate the account like this <code>Account depo = new DepositAccount(individual, 400, 0.7);</code> the function Withdraw is gone. Should I make <code>Withdraw</code> virtual? But i only need it for the DepositAccounts. I am so confused.</p>