| using System;
public enum AccountTransaction {Withdrawing, Depositing, Interests};
public class BankAccount {
private double interestRate;
private string owner;
private decimal balance;
public BankAccount(string owner): this(owner, 0.0) {
}
public BankAccount(string owner, double interestRate) {
this.interestRate = interestRate;
this.owner = owner;
this.balance = 0.0M;
}
public decimal Balance () {
return balance;
}
private void LogTransaction(AccountTransaction kind, DateTime dt,
decimal amount){
// It is an exercise to implement this method
}
public void Withdraw (decimal amount) {
this.LogTransaction(AccountTransaction.Withdrawing,
DateTime.Now, amount);
balance -= amount;
}
public void Deposit (decimal amount) {
this.LogTransaction(AccountTransaction.Depositing,
DateTime.Now, amount);
balance += amount;
}
public void AddInterests() {
decimal interests = balance * (decimal)interestRate;
this.LogTransaction(AccountTransaction.Interests,
DateTime.Now, interests);
balance += interests;
}
public override string ToString() {
return owner + "'s account holds " +
+ balance + " kroner";
}
} |