Skip to content

Instantly share code, notes, and snippets.

@Cellane
Last active December 16, 2015 05:19
Show Gist options
  • Save Cellane/5383965 to your computer and use it in GitHub Desktop.
Save Cellane/5383965 to your computer and use it in GitHub Desktop.
using System;
namespace FirstTask
{
class BankAccount
{
private readonly int _accountNumber;
private readonly int _bankCode;
private decimal _balance;
private readonly Currency _currency;
private readonly bool _overdraftEnabled;
public BankAccount(int accountNumber, int bankCode, decimal balance, Currency currency, bool overdraftEnabled)
{
_accountNumber = accountNumber;
_bankCode = bankCode;
_balance = balance;
_currency = currency;
_overdraftEnabled = overdraftEnabled;
}
public void Insert(decimal amount)
{
_balance += amount;
}
public void Withdraw(decimal amount)
{
if (_balance - amount <= 0 && !_overdraftEnabled)
{
Console.WriteLine("Ouch, no can dosville, baby doll!");
return;
}
_balance -= amount;
}
public void Do(OperationType operationType, decimal amount)
{
var method = GetType().GetMethod(operationType.ToString());
method.Invoke(this, new object[] {amount});
}
public void PrintBalance()
{
Console.WriteLine("Account number: {0}/{1}", _accountNumber, _bankCode);
Console.ForegroundColor = _balance >= 0 ? ConsoleColor.Green : ConsoleColor.Red;
Console.WriteLine("Balance: {0} {1}", _balance, _currency);
Console.ForegroundColor = ConsoleColor.White;
}
internal enum Currency
{
CZK, USD, EUR, ZAR
}
internal enum OperationType
{
Insert, Withdraw
}
}
}
using System;
namespace FirstTask
{
class Program
{
static void Main()
{
var firstBankAccount = new BankAccount(123456, 789, 100, BankAccount.Currency.CZK, false);
var secondBankAccount = new BankAccount(654321, 987, 1000, BankAccount.Currency.ZAR, true);
SetUpConsole();
firstBankAccount.Do(BankAccount.OperationType.Insert, 100);
firstBankAccount.Do(BankAccount.OperationType.Withdraw, 250);
firstBankAccount.PrintBalance();
secondBankAccount.Do(BankAccount.OperationType.Withdraw, 10000);
secondBankAccount.PrintBalance();
Console.ReadLine();
}
private static void SetUpConsole()
{
Console.ForegroundColor = ConsoleColor.White;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment