Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    The class BankAccount - without owner.Lecture 5 - slide 15 : 29
Program 2
using System;

public class BankAccount {

   private double interestRate;    
   private decimal balance;        
                                   
   public BankAccount(double interestRate, decimal balance) {
      this.interestRate = interestRate;
      this.balance = balance;
   }   

   public decimal Balance () {
      return balance;
   }

   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 "The account holds " + balance + " kroner";
   }
} 
 
 
 
 
The owner of the bank account
is now dealt with external to  
the BankAccount class.