Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            SavingsAccount  savings  = new SavingsAccount(5.00m, .005m);
            CheckingAccount checking = new CheckingAccount(5.00m, 2.50m);
            decimal         ammount;

            Console.WriteLine("How much would you like to deposit to the savings account?");
            ammount = Convert.ToDecimal(Console.ReadLine());
            savings.Credit(ammount);
            Console.WriteLine("The new balance is: " + savings.Balance);
            Console.WriteLine("How much would you like to deposit to checking?");
            ammount = Convert.ToDecimal(Console.ReadLine());
            checking.Credit(ammount);
            Console.WriteLine("The new balance is: " + checking.Balance);

            Console.WriteLine("How much would you like to withdraw the savings account?");
            ammount = Convert.ToDecimal(Console.ReadLine());
            savings.Debit(ammount);
            Console.WriteLine("The new balance is: " + savings.Balance);
            Console.WriteLine("How much would you like to withdraw from checking?");
            ammount = Convert.ToDecimal(Console.ReadLine());
            checking.Debit(ammount);
            Console.WriteLine("The new balance is: " + checking.Balance);

            Console.WriteLine("The ammount of interest earned from savings is: " + savings.CalculateInterest());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            CurrentAccount current1 = new CurrentAccount("yomi", 23345, "gtb", 1000M);

            Console.WriteLine($"{current1.Balance:C}");
            current1.Credit(200m);
            Console.WriteLine($"{current1.Balance:C}");
            //   Console.WriteLine(current1);


            SavingsAccount savings1 = new SavingsAccount("james stayrt", 0292020, "Uba", 500m, 0.02m);

            Console.WriteLine($"{savings1.Balance:C}");
            decimal intrest1 = savings1.CalculateInterest();

            savings1.Credit(intrest1);
            Console.WriteLine($"{savings1.Balance:C}");
            // Console.WriteLine(savings1);

            SavingsAccount savings2 = new SavingsAccount("Kenny Show", 5677, "Union Bank", 500m, 0.03m);

            Console.WriteLine($"{savings2.Balance:C}");
            decimal intrest2 = savings2.CalculateInterest();

            savings2.Credit(intrest2);
            Console.WriteLine($"{savings2.Balance:C}");

            List <Account> accounts = new List <Account> {
                current1, savings1, savings2
            };

            Console.WriteLine("==============Looping through Accounts polymorphically============= ");


            foreach (var account in accounts)
            {
                if (account is SavingsAccount)
                {
                    var     savings     = (SavingsAccount)account;
                    decimal intrestRate = savings.CalculateInterest();
                    savings.Credit(intrestRate);
                    Console.WriteLine($"Intrest Added To Savings Account: {intrestRate:C}");
                }

                Console.WriteLine($"Account Balance {account.Balance:C}");
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            SavingsAccount account1 = new SavingsAccount("James Stuart", "0027476177", 40000m, 0.03);

            CurrentAccount account2 = new CurrentAccount("Abayomi Igwubor", "0027476177", 30000m);

            List <Account> accounts = new List <Account>()
            {
                account1, account2
            };

            Console.Write("Welcome to Access Bank PLC!\nEnter type of transaction (Debit or Credit): ");
            string TransactionType = Console.ReadLine();

            Console.Write("Enter amount: ");
            decimal Amount = Convert.ToDecimal(Console.ReadLine());

            foreach (var account in accounts)
            {
                if (TransactionType.ToUpper() == "CREDIT")
                {
                    if (account is SavingsAccount)
                    {
                        SavingsAccount savings = account as SavingsAccount;
                        savings.CalculateInterest();
                    }
                    account.Credit(Amount);
                    Console.WriteLine(account);
                }
                else if (TransactionType.ToUpper() == "DEBIT")
                {
                    account.Debit(Amount);
                    Console.WriteLine(account);
                }
                Console.WriteLine("=========================\n");
            }
        }