Initial transfer of larger repo from git. IF full history and branches are needed must go to github at https://github.com/DulcisL/CCUCoding.git
This commit is contained in:
commit
c09ce40be0
4048 files changed
+603256
No files matched your search
@@ -0,0 +1,69 @@
|
||||
namespace Classes;
|
||||
|
||||
public class BankAccount
|
||||
{
|
||||
private static int s_accountNumberSeed = 1234567890;
|
||||
public string Number { get; }
|
||||
public string Owner { get; set; }
|
||||
public decimal Balance
|
||||
{
|
||||
get
|
||||
{
|
||||
decimal balance = 0;
|
||||
foreach (var item in _allTransactions)
|
||||
{
|
||||
balance += item.Amount;
|
||||
}
|
||||
return balance;
|
||||
}
|
||||
}
|
||||
private List<Transaction> _allTransactions = new List<Transaction>();
|
||||
|
||||
public BankAccount(string name, decimal initialBalance)
|
||||
{
|
||||
Number = s_accountNumberSeed.ToString();
|
||||
s_accountNumberSeed++;
|
||||
|
||||
Owner = name;
|
||||
MakeDeposit(initialBalance, DateTime.Now, "Initial balance");
|
||||
}
|
||||
|
||||
public void MakeDeposit(decimal amount, DateTime date, string note)
|
||||
{
|
||||
if (amount <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(amount), "Amount of deposit must be positive");
|
||||
}
|
||||
var deposit = new Transaction(amount, date, note);
|
||||
_allTransactions.Add(deposit);
|
||||
}
|
||||
|
||||
public void MakeWithdrawal(decimal amount, DateTime date, string note)
|
||||
{
|
||||
if (amount <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(amount), "Amount of withdrawal must be positive");
|
||||
}
|
||||
if (Balance - amount < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Not sufficient funds for this withdrawal");
|
||||
}
|
||||
var withdrawal = new Transaction(-amount, date, note);
|
||||
_allTransactions.Add(withdrawal);
|
||||
}
|
||||
|
||||
public string GetAccountHistory()
|
||||
{
|
||||
var report = new System.Text.StringBuilder();
|
||||
|
||||
decimal balance = 0;
|
||||
report.AppendLine("Date\t\tAmount\tBalance\tNote");
|
||||
foreach (var item in _allTransactions)
|
||||
{
|
||||
balance += item.Amount;
|
||||
report.AppendLine($"{item.Date.ToShortDateString()}\t{item.Amount}\t{balance}\t{item.Notes}");
|
||||
}
|
||||
|
||||
return report.ToString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user