Inheritance: Account, IDepositable, IWithDrawable
Beispiel #1
1
        static void Main()
        {
            DepositAccount myDeposit = new DepositAccount(Customer.Individual, 0, 1);
            myDeposit.Deposit(2500);

            Console.WriteLine("Balance: {0}", myDeposit.Balance);
            Console.WriteLine("Interest: {0}", myDeposit.CalculateInterest(12));

            Console.WriteLine("... Withdrawing $2000 ...");
            myDeposit.Withdraw(-2000);
            // myDeposit.Withdraw(-2800); - this will throw exeption

            Console.WriteLine("New Balance {0}", myDeposit.Balance);
            Console.WriteLine("new Interest: {0}", myDeposit.CalculateInterest(12));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            List <IAccount> accounts = new List <IAccount>();

            ICustomer person  = new Individual("Mihai Irimia", 1911122284548);
            ICustomer company = new Company("Polaris-Palmax", "1234RO436534");

            DateTime noOfDays = new DateTime(2018, 10, 3, 0, 0, 0);

            IAccount depositAccount  = new DepositAccount(person, 10000, 10, noOfDays); // noOfMonths = 4
            IAccount loanAccount     = new LoanAccount(company, 100, 5, noOfDays);
            IAccount mortgageAccount = new MortgageAccount(company, 1000, 10, noOfDays);

            accounts.Add(depositAccount);
            accounts.Add(loanAccount);
            accounts.Add(mortgageAccount);

            foreach (var elem in accounts)
            {
                elem.Print();
            }


            Console.ReadKey();
        }
        /*2.	A bank holds different types of accounts for its customers:
         * deposit accounts, loan accounts and mortgage accounts. Customers could be individuals or companies.*/
        /*All accounts have customer, balance and interest rate (monthly based).
         * Deposit accounts are allowed to deposit and with draw money.
         * Loan and mortgage accounts can only deposit money.*/
        /*All accounts can calculate their interest amount for a given period (in months).
         * In the common case its is calculated as follows: number_of_months * interest_rate.*/
        /*Loan accounts have no interest for the first 3 months
         * if are held by individuals and for the first 2 months if are held by a company.*/
        /* Deposit accounts have no interest if their balance is positive and less than 1000. */
        /* Mortgage accounts have ½ interest for the first 12 months for companies and no interest for the first 6 months for individuals.*/
        static void Main()
        {
            //create customers
            Person person = new Person("Tervel", "Kubratov", "Sofia");
            Person someone = new Person("King", "Arthur", "Dublin");
            Company company = new Company("Tervel OOD", "Sofia", TypeOfFirm.LTD);

            //create aacounts, interest 3% = 0.03M
            DepositAccount depositPerson = new DepositAccount(person, 450.00M, 0.03M, 4);
            depositPerson.Balance = depositPerson.DepositeMoney(2400M);
            Console.WriteLine("Balance of {0} is {1:C3}", person.FirstName, depositPerson.Balance);
            Console.WriteLine("Interest Amount of deposit {0} is {1}", person.FirstName, depositPerson.CalculateInterestAmount());
            LoanAccount loanPerson = new LoanAccount(person, 3200.0M, 0.04M, 13);
            Console.WriteLine("Interest Amount of loan {0} is {1}", person.FirstName, loanPerson.CalculateInterestAmount());
            MortgageAccount mortgagePerson = new MortgageAccount(person, 5060.80M, 0.05M, 14);
            Console.WriteLine("Interest Amount of mortgage {0} is {1}", person.FirstName, mortgagePerson.CalculateInterestAmount());

            Console.WriteLine();
            DepositAccount depositSomeone = new DepositAccount(someone, 3000.50M, 0.023M, 2);
            Console.WriteLine("Balance of {0} is {1:C3}", someone.FirstName, depositSomeone.Balance);

            Console.WriteLine();
            DepositAccount depositSome = new DepositAccount(company, 500.0M, 0.07M, 5);
            Console.WriteLine("Balance of \"{0}\" is {1:C3}", company.CompanyName, depositSome.Balance);
            Console.WriteLine("Interest Amount of deposit {0} is {1}", company.CompanyName, depositSome.CalculateInterestAmount());
            MortgageAccount mortgageCompany = new MortgageAccount(company, 2500.00M, 0.05M, 13);
            Console.WriteLine("Interest Amount of mortgage {0} is {1}", company.CompanyName, mortgageCompany.CalculateInterestAmount());
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Account deposit1 = new DepositAccount(new Individual(), 500m, 3.5m);
            Account deposit2 = new DepositAccount(new Company(), 1500m, 3.4m);

            Console.WriteLine(deposit1.CalculateInterestAmount(2)); // 0
            Console.WriteLine(deposit2.CalculateInterestAmount(2)); // 6.8

            Account loan1 = new LoanAccount(new Individual(), 1000m, 5m);
            Account loan2 = new LoanAccount(new Company(), 1000m, 5m);

            Console.WriteLine(loan1.CalculateInterestAmount(2)); // 0
            Console.WriteLine(loan1.CalculateInterestAmount(4)); // 20
            Console.WriteLine(loan2.CalculateInterestAmount(1)); // 0
            Console.WriteLine(loan2.CalculateInterestAmount(3)); // 15

            Account mortgage1 = new MortgageAccount(new Individual(), 1000m, 5m);
            Account mortgage2 = new MortgageAccount(new Company(), 1000m, 5m);

            Console.WriteLine(mortgage2.CalculateInterestAmount(11)); // 65 / 2 = 27.5
            Console.WriteLine(mortgage2.CalculateInterestAmount(13)); // 65
            Console.WriteLine(mortgage1.CalculateInterestAmount(5));  // 0
            Console.WriteLine(mortgage1.CalculateInterestAmount(7));  // 35

            Individual customer1 = new Individual("Pesho");
            Company    customer2 = new Company("Telerik");

            Console.WriteLine(customer1.Name); // Pesho
            Console.WriteLine(customer2.Name); // Telerik
        }
        public static void Main()
        {
            LoanAccount     lAccount = new LoanAccount("Gosho Goshev", CustomerTypes.individual, 23423, 3);
            DepositAccount  dAccount = new DepositAccount("Company", CustomerTypes.company, 44321, 1.75m);
            MortgageAccount mAccount = new MortgageAccount("Any individual", CustomerTypes.individual, -234, 2.99m);

            Console.WriteLine("Loan account interest amont for 5 months: {0}", lAccount.InterestAmount(5));
            Console.WriteLine("Deposit account interest amont for 3 months: {0}", dAccount.InterestAmount(3));
            Console.WriteLine("Mortgage account interest amont for 7 months: {0}", mAccount.InterestAmount(7));
        }
Beispiel #6
0
 private static void Main()
 {
     var testAcc = new DepositAccount(Customer.Company, 10000000M, 0.5M);
     Console.WriteLine(testAcc);
     var secondTest = new LoanAccount(Customer.Individual, 10000M, 1M);
     Console.WriteLine(secondTest);
     Console.WriteLine(secondTest.CalcInterestAmount(6));
     secondTest.Deposit(503.56M);
     Console.WriteLine(secondTest);
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            Customers      mycustomer = new Customers("Peter", CustomerType.individuals);
            DepositAccount mydeposit  = new DepositAccount(mycustomer, 4000, 2.5m, new DateTime(2019, 01, 23));

            Console.WriteLine(mydeposit.MakeWithdrawal(500m));
            Console.WriteLine(mydeposit.CalculateInterest());
            //Console.WriteLine(DateTime.Now.Month);
            Console.ReadKey();
        }
Beispiel #8
0
        static void Main()
        {
            Customer IvanIvanov     = new IndividualCustomer("Ivan Ivanov");
            Customer PetarStoyanov  = new IndividualCustomer("Petar Stoyanov");
            Customer AnnaVasileva   = new IndividualCustomer("Anna Vasileva");
            Customer MariaAtanasova = new IndividualCustomer("Maria Atanasova ");
            Customer CocaCola       = new CompanyCustomer("CocaCola");
            Customer Microsoft      = new CompanyCustomer("Microsoft");
            Customer Apple          = new CompanyCustomer("Apple");
            Customer Google         = new CompanyCustomer("Google");

            DepositAccount depositIvanIvanov    = new DepositAccount(IvanIvanov, 800m, 0.05m);
            DepositAccount depositCocaCola      = new DepositAccount(CocaCola, 5000000m, 0.02m);
            LoanAccount    loanAnnaVasilev      = new LoanAccount(AnnaVasileva, -10000m, 0.12m);
            LoanAccount    loanGoogle           = new LoanAccount(Google, -1000000m, 0.08m);
            MortageAccount mortagePetarStoyanov = new MortageAccount(PetarStoyanov, -50000m, 0.07m);
            MortageAccount mortageMictosoft     = new MortageAccount(Microsoft, -5000000m, 0.06m);

            IList <Account> accounts = new List <Account>();

            accounts.Add(depositIvanIvanov);
            accounts.Add(depositCocaCola);
            accounts.Add(loanAnnaVasilev);
            accounts.Add(loanGoogle);
            accounts.Add(mortagePetarStoyanov);
            accounts.Add(mortageMictosoft);

            foreach (var account in accounts)
            {
                Console.WriteLine(account);
            }

            depositIvanIvanov.WithDraw(258.15m);
            Console.WriteLine("\nInterest for next 4 mounts:");
            foreach (var account in accounts)
            {
                Console.WriteLine(account + " " + account.InterestAmount(4));
            }

            depositIvanIvanov.Deposit(800m);
            loanAnnaVasilev.Deposit(600.12m);
            mortagePetarStoyanov.Deposit(1825.12m);
            Console.WriteLine("\nInterest for next 8 mounts:");
            foreach (var account in accounts)
            {
                Console.WriteLine(account + " " + account.InterestAmount(8));
            }

            Console.WriteLine("\nInterest for next 20 mounts:");
            foreach (var account in accounts)
            {
                Console.WriteLine(account + " " + account.InterestAmount(20));
            }
        }
Beispiel #9
0
        private static void Main()
        {
            var testAcc = new DepositAccount(Customer.Company, 10000000M, 0.5M);

            Console.WriteLine(testAcc);
            var secondTest = new LoanAccount(Customer.Individual, 10000M, 1M);

            Console.WriteLine(secondTest);
            Console.WriteLine(secondTest.CalcInterestAmount(6));
            secondTest.Deposit(503.56M);
            Console.WriteLine(secondTest);
        }
Beispiel #10
0
        static void Main()
        {
            List <Account> allAccounts = new List <Account>();

            Account morgageCompany1 = new MorgageAccount(Customer.company, 569.66M, 2.3M);

            morgageCompany1.Deposit(1000M);
            Account loanIndividual = new LoanAccount(Customer.individual, 896.366M, 5.66M);
            Account depositCompany = new DepositAccount(Customer.company, 4569.55M, 8.3M);

            allAccounts.Add(morgageCompany1);
            allAccounts.Add(loanIndividual);
            allAccounts.Add(depositCompany);
            PrintAccounts(allAccounts);
        }
Beispiel #11
0
        static void Main()
        {
            DepositAccount myDeposit = new DepositAccount(Customer.Individual, 0, 1);

            myDeposit.Deposit(2500);

            Console.WriteLine("Balance: {0}", myDeposit.Balance);
            Console.WriteLine("Interest: {0}", myDeposit.CalculateInterest(12));

            Console.WriteLine("... Withdrawing $2000 ...");
            myDeposit.Withdraw(-2000);
            // myDeposit.Withdraw(-2800); - this will throw exeption

            Console.WriteLine("New Balance {0}", myDeposit.Balance);
            Console.WriteLine("new Interest: {0}", myDeposit.CalculateInterest(12));
        }
Beispiel #12
0
        static void Main()
        {
            var bajPesho    = Customer.Individual;
            var leliaMarche = Customer.Individual;
            var mrAnderson  = Customer.Individual;

            var google    = Customer.Company;
            var microsoft = Customer.Company;
            var facebook  = Customer.Company;

            var bajPeshoAccount    = new DepositAccount(bajPesho, 200, 7);
            var leliaMarcheAccount = new MortgageAccount(leliaMarche, 200, 7);
            var mrAndersonAccount  = new LoanAccount(mrAnderson, 200, 7);

            var googleAccount    = new DepositAccount(google, 200, 7);
            var microsoftAccount = new MortgageAccount(microsoft, 200, 7);
            var facebookAccount  = new LoanAccount(facebook, 200, 7);

            googleAccount.Withdraw(100);
            // Console.WriteLine(googleAccount.Balance);
            facebookAccount.Deposit(100);
            // Console.WriteLine(facebookAccount.Balance);

            var accounts = new List <IAccount>()
            {
                googleAccount,
                microsoftAccount,
                facebookAccount,
                bajPeshoAccount,
                leliaMarcheAccount,
                mrAndersonAccount
            };

            var sortedAccounts = accounts.OrderByDescending(account => account.Balance);

            foreach (var account in sortedAccounts)
            {
                decimal interestFirstMonths = account.CalculateInterest(3);
                decimal interest            = account.CalculateInterest(13);

                Console.WriteLine("customer: {0} - balance: {1}; first months interest: {2}; interest: {3}"
                                  , account.Customer, account.Balance, interestFirstMonths, interest);
            }
        }
Beispiel #13
0
        public static void Main()
        {
            var client = new Individual("Client", "Sofia", 23);
            var account = new DepositAccount(client, 1000, 2);
            Console.WriteLine(account.Balance);
            //making a deposit of 100
            account.Deposit(100);
            //money after the deposit
            Console.WriteLine(account.Balance);
            //interest after 14months
            Console.WriteLine(account.CalculaterInterest(14));
            //making a withdraw
            account.Withdraw(500);
            Console.WriteLine(account.Balance);

            var account1 = new LoanAccount(new Company("ComapanySoft", "Varna", "1024443"), 10400, 7);
            //interest after 6months
            Console.WriteLine(account1.CalculaterInterest(6));
        }
Beispiel #14
0
        public static void Main()
        {
            DepositAccount kiro = new DepositAccount(Customers.Individual, 1000m, 5);
            Console.WriteLine(kiro.CalculateInterest(10) + "\n");

            LoanAccount pesho = new LoanAccount(Customers.Individual, 1500m, 3);
            Console.WriteLine(pesho.CalculateInterest(12) + "\n");

            LoanAccount maglaOOD = new LoanAccount(Customers.Company, 1500m, 3);
            Console.WriteLine(maglaOOD.CalculateInterest(12) + "\n");

            MortgageAccount penka = new MortgageAccount(Customers.Individual, 50000m, 2);
            Console.WriteLine(penka.CalculateInterest(8) + "\n");

            MortgageAccount shadyAD = new MortgageAccount(Customers.Company, 250000m, 5);
            Console.WriteLine(penka.CalculateInterest(12) + "\n");

            MortgageAccount shadyOOD = new MortgageAccount(Customers.Company, 250000m, 5);
            Console.WriteLine(penka.CalculateInterest(24) + "\n");
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            var b = new Bank("ING");

            var c1 = new Individual();

            var d = new DepositAccount(b, c1, 1000, 3.85m, 12);

            Console.WriteLine(d.CalculateInterest());


            var l = new LoanAccount(b, c1, 1000, 3.5m, 12);

            Console.WriteLine(l.CalculateInterest());

            var c2 = new Company();
            var m  = new MortgageAccount(b, c2, 1500, 3.8m, 36);

            Console.WriteLine(m.CalculateInterest());
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            //新建一个个人存款账户
            DepositAccount A = new DepositAccount("WHM", 0);

            //存款
            A.Deposit(20000);
            //取款
            A.Withdraw(5000);
            //获得利息
            Console.WriteLine("您的利息为:{0}。", A.GetInterest(18, 0.035));
            //新建一个企业贷款账户
            LoanAccount B = new LoanAccount("WH", 1);

            //存款
            B.Deposit(20000);
            //获得利息
            Console.WriteLine("您的利息为:{0}。", B.GetInterest(27, 0.037));
            //抵押贷款同理,此处不给出
        }
Beispiel #17
0
        public Account CreateAccount(Client client, double?limit, DateTime?dateTime)
        {
            Decorator decorator = new Decorator();
            Account   resultAccount;

            if (limit != null)
            {
                resultAccount = new CreditAccount(client, (double)limit, creditLimit);
            }
            else
            {
                if (dateTime != null)
                {
                    resultAccount = new DepositAccount(client, (DateTime)dateTime, depositPercent);
                }
                else
                {
                    resultAccount = new CurrentAccount(client, currentPercent);
                }
            }

            return(resultAccount);
        }
Beispiel #18
0
        static void Main()
        {
            DepositAccount depositPersonAcc = new DepositAccount(Customer.Individual, 10000.00M, 2.5);

            Console.WriteLine("Individual deposit account(balance = {0}) interest for 12 months = {1:F2}."
                              , depositPersonAcc.Balance, depositPersonAcc.CalculateInterest(12));
            Console.WriteLine("Withdrawing from this account 9500.");
            depositPersonAcc.Withdraw(9500);
            Console.WriteLine("Individual deposit account(balance = {0}) interest for 12 months = {1:F2}."
                              , depositPersonAcc.Balance, depositPersonAcc.CalculateInterest(12));
            Console.WriteLine("Try to withdraw 501.");
            depositPersonAcc.Withdraw(501);

            LoanAccount loanPersonAcc  = new LoanAccount(Customer.Individual, -15250.35M, 2.0);
            LoanAccount loanCompanyAcc = new LoanAccount(Customer.Company, -50000, 1.5);

            Console.WriteLine("\nIndividual loan account(balance = {0}) interest for 3 months = {1:F2}."
                              , loanPersonAcc.Balance, loanPersonAcc.CalculateInterest(3));
            Console.WriteLine("Individual loan account(balance = {0}) interest for 10 months = {1:F2}."
                              , loanPersonAcc.Balance, loanPersonAcc.CalculateInterest(10));
            Console.WriteLine("Company loan account(balance = {0}) interest for 10 months = {1:F2}."
                              , loanCompanyAcc.Balance, loanCompanyAcc.CalculateInterest(10));
            Console.WriteLine("Company loan account(balance = {0}) interest for 2 months = {1:F2}."
                              , loanCompanyAcc.Balance, loanCompanyAcc.CalculateInterest(2));

            MortgageAccount mortgagePersonAcc  = new MortgageAccount(Customer.Individual, -2500.50M, 3.2);
            MortgageAccount mortgageCompanyAcc = new MortgageAccount(Customer.Company, -1000M, 1);

            Console.WriteLine("\nIndividual mortgage account(balance = {0}) interest for 6 months = {1:F2}."
                              , mortgagePersonAcc.Balance, mortgagePersonAcc.CalculateInterest(6));
            Console.WriteLine("Individual mortgage account(balance = {0}) interest for 10 months = {1:F2}."
                              , mortgagePersonAcc.Balance, mortgagePersonAcc.CalculateInterest(10));
            Console.WriteLine("Individual mortgage account(balance = {0}) interest for 12 months = {1:F2}."
                              , mortgageCompanyAcc.Balance, mortgageCompanyAcc.CalculateInterest(12)); //for first 12 months interest is 60$
            Console.WriteLine("Individual mortgage account(balance = {0}) interest for 24 months = {1:F2}."
                              , mortgageCompanyAcc.Balance, mortgageCompanyAcc.CalculateInterest(24)); //for 24 months interest is 60$ for first 12months + 120$ for next 12 months
        }
Beispiel #19
0
        public static void Main()
        {
            ICustomer pesho       = new IndividualCustomer("Petar Petrov");
            ICustomer agroCompany = new CompanyCustomer("Agro Company Ltd.");

            IAccount mortgageAccInd     = new MortgageAccount(pesho, 1024m, 5.3m);
            IAccount mortgageAccComp    = new MortgageAccount(agroCompany, 1024m, 5.3m);
            IAccount loanAccInd         = new LoanAccount(pesho, 1024m, 5.3m);
            IAccount loanAccComp        = new LoanAccount(agroCompany, 1024m, 5.3m);
            IAccount depositAccIndBig   = new DepositAccount(pesho, 1024m, 5.3m);
            IAccount depositAccIndSmall = new DepositAccount(pesho, 999m, 5.3m);
            IAccount depositAccComp     = new DepositAccount(agroCompany, 11024m, 4.3m);

            List <IAccount> accounts = new List <IAccount>()
            {
                mortgageAccInd,
                mortgageAccComp,
                loanAccInd,
                loanAccComp,
                depositAccIndBig,
                depositAccIndSmall,
                depositAccComp
            };

            foreach (var acc in accounts)
            {
                Console.WriteLine(
                    "{5} {0,-15}: {1:N2}, {2:N2}, {3:N2}, {4:N2}",
                    acc.GetType().Name,
                    acc.CalculateRate(2),
                    acc.CalculateRate(3),
                    acc.CalculateRate(10),
                    acc.CalculateRate(13),
                    acc.Customer.GetType().Name);
            }
        }
Beispiel #20
0
        public void TestAccountConstructor4_ThrowsException()
        {
            Customer accountCustomer = new IndividualCustomer(
                "2343PJ34752",
                "William",
                "Harris",
                "1 Microsoft Way, Redmond, WA",
                "1-888-553-6562");

            Account account = new DepositAccount(
                accountCustomer,
                2500,
                -1.0825M,
                12);
        }
Beispiel #21
0
        public void TestWithdrawMethod()
        {
            Customer accountCustomer = new IndividualCustomer(
                "2343PJ34752",
                "William",
                "Harris",
                "1 Microsoft Way, Redmond, WA",
                "1-888-553-6562");

            DepositAccount account = new DepositAccount(
                accountCustomer,
                2500,
                1.0825M,
                12);

            account.Withdraw(400M);

            Assert.AreEqual(2100M, account.Balance);
        }
Beispiel #22
0
        public void TestDepositMethod()
        {
            Customer accountCustomer = new IndividualCustomer(
                "2343PJ34752",
                "William",
                "Harris",
                "1 Microsoft Way, Redmond, WA",
                "1-888-553-6562");

            Account account = new DepositAccount(
                accountCustomer,
                32500,
                1.0825M,
                12);

            account.Deposit(459M);

            Assert.AreEqual(32959M, account.Balance);
        }
Beispiel #23
0
        public void TestAccountConstructor2()
        {
            Customer accountCustomer = new IndividualCustomer(
                "2343PJ34752",
                "William",
                "Harris",
                "1 Microsoft Way, Redmond, WA",
                "1-888-553-6562");

            Account account = new DepositAccount(
                accountCustomer,
                2500,
                1.0825M,
                12);

            Assert.AreEqual(1.0825M, account.MonthlyInterestRate);
        }