예제 #1
0
 protected Account(Customer customer)
 {
     PrimaryAccountHolder = customer;
     AccountHolders.Add(PrimaryAccountHolder);
     AccountNumber = String.Format($"{++anb,0:D4}");
     Balance       = 0;
     AllAccounts.Add(this);
 }
예제 #2
0
        public void PayInterest()
        {
            decimal interest = Balance >= MinBalForInterest ? Balance * InterestRate : 0M;

            if (interest > 0)
            {
                Deposit(interest);
            }
            AllAccounts.LogTransaction(this, interest, "Interest");
        }
예제 #3
0
 public void Withdraw(decimal amount)
 {
     if (Balance - amount >= 0)
     {
         Balance -= amount;
     }
     else
     {
         AllAccounts.LogTransaction(this, amount, "Withdrawal", "DECLINED");
     }
 }
예제 #4
0
        static void Main(string[] args)
        {
            Customer C = new Customer {
                Name = "Test1"
            };
            IAccount AC = new CurrentAccount(C);

            AC.Deposit(500M);
            AC.Withdraw(34.99M);

            C = new Customer {
                Name = "Test2"
            };
            CurrentAccount NAC;

            NAC = new CurrentAccount(C);
            NAC.OverdraftLimit = 200M;
            NAC.Withdraw(200M);
            NAC.Deposit(149.99M);

            C = new Customer {
                Name = "Test2"
            };
            AC = new SavingsAccount(C);
            AC.Deposit(149.99M);
            foreach (int i in Enumerable.Range(1, 3))
            {
                AC.Withdraw(50M);
            }

            PremiumSavingsAccount PSA;

            PSA = new PremiumSavingsAccount(new Customer()
            {
                Name = "G Mugabe"
            });
            PSA.Deposit(1000M);
            PSA.PayInterest();
            PSA.Withdraw(900M);
            PSA.PayInterest();

            NAC = new CurrentAccount(
                new List <Customer>()
            {
                new Customer()
                {
                    Name = "Tom"
                },
                new Customer()
                {
                    Name = "Dick"
                },
                new Customer()
                {
                    Name = "Harry"
                }
            });


            AllAccounts.ListAll();

            AllAccounts.ListOne(NAC);
            Console.ReadKey();
        }