using System.Collections.Generic;
public BankAccount(string owner, double balance)
if (balance < 0) throw new Exception("Cannot create account with negative balance");
AllBankAccounts.Add(this);
public void TransferIn(double amount, BankAccount other)
if (amount < 0) throw new Exception("amount must be positive");
if (other.Balance < amount) throw new Exception("Insufficient funds in other account");
public void TransferOut(double amount, BankAccount other)
if (amount < 0) throw new Exception("amount must be positive");
if (Balance < amount) throw new Exception("Insufficient funds in your account");
public static void ChargeMonthlyFees()
for (var i = 1; i < AllBankAccounts.Count; i++)
AllBankAccounts[1].TransferOut(15, AllBankAccounts[0]);
public static void EarnInterest()
for (var i = 1; i < AllBankAccounts.Count; i++)
var interest = AllBankAccounts[i].Balance * 0.05;
AllBankAccounts[i].TransferIn(interest, AllBankAccounts[0]);
Console.WriteLine( $"{Owner} has ${Balance}");
public static void PrintAllBankAccounts()
for (var i = 0; i < AllBankAccounts.Count; i++)
AllBankAccounts[i].Print();
public string Owner { get; private set; }
public double Balance { get; private set; }
public static List<BankAccount> AllBankAccounts { get; } = new List<BankAccount>();
static void Main(string[] args)
var bankAccount = new BankAccount("Bank", 10000000);
var account1 = new BankAccount("Joe", 100);
var account2 = new BankAccount("Billy", 200);
BankAccount.PrintAllBankAccounts();
BankAccount.ChargeMonthlyFees();
BankAccount.EarnInterest();
BankAccount.PrintAllBankAccounts();