using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BankSystem { public class BankAccountEventArgs : EventArgs { private double transactionAmount; private DateTime timestamp; public BankAccountEventArgs(double transactionAmount) { this.transactionAmount = transactionAmount; timestamp = DateTime.Now; } public override string ToString() { return string.Format("Transaction amount {0}, timestamp {1}", transactionAmount, timestamp); } } public class BankAccount { // Fields. private string accountHolder; private double balance; // Events. public event EventHandler ProtectionLimitExceeded; public event EventHandler Overdrawn; // Methods etc. public BankAccount(string accountHolder) { this.accountHolder = accountHolder; this.balance = 0; } public void Deposit(double amount) { balance += amount; // If balance has exceeded the government's protection limit, raise a ProtectionLimitExceeded event. if (balance >= 50000 && ProtectionLimitExceeded != null) { ProtectionLimitExceeded(this, new BankAccountEventArgs(amount)); } } public void Withdraw(double amount) { balance -= amount; // If account is now negative, raise an Overdrawn event. if (balance < 0 && Overdrawn != null) { Overdrawn(this, new BankAccountEventArgs(amount)); } } public override string ToString() { return string.Format("Account {0}, balance {1}", accountHolder, balance); } } }