using System;
///
/// A simple bank account created as an everyday example
/// for the OOP course. Used in particular for demonstrating inheritance.
///
public class BankAccount {
private double interestRate;
private string owner;
private double balance;
///
/// Construct a bank account from owner.
/// The interestRate is given the default value 0.0.
/// The balance is given the default value 0.0.
///
/// The owners name. A string.
public BankAccount(string owner):
this(owner, 0.0, 0.0) {
}
///
/// Construct a bank account from owner, balance, and interestRate.
/// The interestRate is given the default value 0.0.
///
/// The owners name
/// The initial amount of this account
public BankAccount(string owner, double balance):
this(owner, balance, 0.0) {
}
///
/// Construct a bank account from owner, balance, and interestRate.
///
/// The owners name
/// The initial amount of this account
///
/// The interest rate.
/// Annual interet is calculated as balance * interestRate
///
public BankAccount(string owner, double balance, double interestRate) {
this.interestRate = interestRate;
this.owner = owner;
this.balance = balance;
}
///
/// Returns the current amount of the bank account
/// without affecting the account.
///
/// Accesses the amount of money in the account
public double Balance {
get{
return balance;
}
}
///
/// Return the interest rate of the account
///
/// Accesses the interest rate of the account
public double InterestRate {
get{
return interestRate;
}
}
///
/// Withdraw an amount of money from the account.
/// This decreases the balance of the account.
///
///
/// The amount of money to withdraw from the account.
/// Precondition: Must be non-negative.
///
public void Withdraw (double amount) {
balance -= amount;
}
///
/// Withdraw an amount of money from the account.
/// This increases the balance of the account.
///
///
/// The amount of money to deposit to the account.
/// Precondition: Must be non-negative.
///
public void Deposit (double amount) {
balance += amount;
}
///
/// Add the annual interest to the account.
/// This may increase the current balance of the account.
///
public void AddInterests() {
balance = balance + balance * interestRate;
}
///
/// Return a text string that represents this account
/// for output purposes
///
public override string ToString() {
return owner + "'s account holds " +
+ balance + " kroner";
}
}