示例#1
0
        public void Withdraw(decimal amount)
        {
            if (amount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), "Amount invalid");
            }
            if (Balance - amount < 0)
            {
                throw new InvalidOperationException("Not sufficient funds");
            }
            var withdrawl = new BankTransaction(-amount);

            allTransactions.Add(withdrawl);
            Console.WriteLine($"Withdraw: {amount}");
        }
示例#2
0
        public void Deposit(decimal amount)
        {
            if (amount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), "Amount invalid");
            }
            var deposit = new BankTransaction(amount);

            decimal balance = GetBalance();

            if (balance == 0)
            {
                Console.WriteLine($"Created a BankAccount with initial balance of {amount}");
            }
            else
            {
                Console.WriteLine($"Deposit: {amount}");
            }
            allTransactions.Add(deposit);
        }