Exemple #1
0
        /// <summary>
        /// Attempts to transfer funds from one BankAccount to another.
        /// </summary>
        /// <param name="other">Destination BankAccount.</param>
        /// <param name="amount">Amount to transfer.</param>
        /// <param name="allowOverdraw">True if the transaction can leave the source account negative.</param>
        /// <returns>True if the transaction succeeded.</returns>
        public bool TryTransferTo(BankAccount other, decimal amount, WithdrawalMode withdrawalMode = WithdrawalMode.RequireFullBalance)
        {
            if (other == null)
            {
                return(false);
            }

            if (TryWithdraw(amount, withdrawalMode))
            {
                other.Deposit(amount);
                return(true);
            }

            return(false);
        }
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            BankAccount account = new BankAccount("123-4567890-12");

            account.Deposit(200);
            WriteToConsole(account);
            account.Withdraw(100);
            WriteToConsole(account);
            IEnumerable <Transaction> transactions = account.GetTransactions(null, null);

            foreach (Transaction item in transactions)
            {
                Console.WriteLine($"Transaction: {item.DateOfTrans} - {item.Amount} - {item.TransactionType}");
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            //BankAccount anotherBA = new BankAccount()
            //{
            //    AccountNumber = "123-124153513-99",
            //    Balance = 200
            //};

            BankAccount myBA = new BankAccount("123-123123123-99", 50);

            Console.WriteLine($"Account number is {myBA.AccountNumber}");
            Console.WriteLine($"Balance is {myBA.Balance} Euro");
            myBA.Deposit(200, 2);
            Console.WriteLine($"Balance is {myBA.Balance} Euro");
            myBA.Withdraw(50);
            Console.WriteLine($"Withdraw cost is {BankAccount.WithdrawCost}");
            Console.WriteLine($"Balance is {myBA.Balance} Euro");
            Console.ReadKey();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            //Object Initializer
            //BankAccount anotherBA = new BankAccount() {
            //    AccountNumber = "123-12312334-99",
            //    Balance = 200
            //};

            BankAccount myBA = new BankAccount("123-12312312-99", 50);

            //Console.WriteLine($"Account number is {myBA.AccountNumber}");
            Console.WriteLine(myBA);
            //Console.WriteLine($"Withdraw cost is {BankAccount.WithdrawCost} Euro");
            //Console.WriteLine($"Balance is {myBA.Balance} Euro.");
            Console.WriteLine(myBA);
            myBA.Deposit(200);
            //Console.WriteLine($"Balance is {myBA.Balance} Euro.");
            Console.WriteLine(myBA);
            myBA.Withdraw(50);
            //Console.WriteLine($"Balance is {myBA.Balance} Euro.");
            Console.WriteLine(myBA);

            //IEnumerable<Transaction> transactions = myBA.Transactions;
            //var transactions = myBA.Transactions;
            foreach (var item in myBA.Transactions)
            {
                Console.WriteLine($"{item.Amount} -- {item.DateOfTransaction} -- {item.TransactionType}");
            }

            var mySA = new SavingsAccount("123-12312312-67", 0.01M);

            mySA.Deposit(1000);
            mySA.AddInterest();
            mySA.Withdraw(10);
            Console.WriteLine($"Balance of savingsAccount: {mySA.Balance}.");

            foreach (var item in mySA.Transactions)
            {
                Console.WriteLine($"{item.Amount} -- {item.DateOfTransaction} -- {item.TransactionType}");
            }

            Console.ReadKey(); //Zodat console niet onmiddelijk afsluit
        }
Exemple #5
0
        static void Main(string[] args)
        {
            // Object Initializer
            //BankAccount anotherBA = new BankAccount()
            //{
            //    AccountNumber = "123-12312334-990",
            //    Balance = 200
            //};

            BankAccount myBa = new BankAccount("123-12312312-99", 50);

            Console.WriteLine($"Account number is {myBa.AccountNumber}.");

            Console.WriteLine($"Balance is {myBa.Balance} Euro");
            myBa.Deposit(200);
            Console.WriteLine($"Balance is {myBa.Balance} Euro");
            myBa.Withdraw(50);
            Console.WriteLine($"Balance is {myBa.Balance} Euro");
            Console.ReadKey();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            IBankAccount account = new BankAccount("123-4567890-12");

            Console.WriteLine($"Accountnumber - Balance: {account.ToString()}");
            //Console.WriteLine($"Balance: {account.Balance}");
            account.Deposit(200M);
            Console.WriteLine($"Balance after deposit of 200€: {account.Balance}");
            account.Withdraw(100M);
            Console.WriteLine($"Balance after withdraw of 100€: {account.Balance}");
            IEnumerable <Transaction> transactions = account.GetTransactions(null, null);

            foreach (Transaction t in transactions)
            {
                Console.WriteLine($"Transactions: {t.DateOfTrans.ToShortDateString()} - {t.Amount}");
            }
            SavingsAccount saving = new SavingsAccount("123-456789-03", 0.01M);

            saving.Deposit(200M);
            saving.Withdraw(100M);
            saving.AddInterest();
            Console.WriteLine($"Balance savingsaccount: {saving.ToString()}");
            Console.ReadKey();
        }