Exemplo n.º 1
0
        protected void btnCalculateLoan_Click(object sender, EventArgs e)
        {
            double remainder;
            int    term, payments;

            if (double.TryParse(txtAmount.Text, out remainder))
            {
                if (int.TryParse(txtTerm.Text, out term))
                {
                    Loan loan = new Loan(Convert.ToDouble(txtAmount.Text), Convert.ToDouble(txtInterest.Text), Convert.ToInt32(txtTerm.Text), Convert.ToInt32(ddlCurrency.SelectedValue));

                    loan.InsertLoan();

                    lblMessage.Text = "Monthly Payment: " + Convert.ToString(loan.CalculatePayment());

                    DataTable  dt = new DataTable();
                    DataColumn dc = new DataColumn();

                    if (dt.Columns.Count == 0)
                    {
                        dt.Columns.Add("Payment", typeof(string));
                        dt.Columns.Add("Collateral", typeof(string));
                        dt.Columns.Add("Interest", typeof(string));
                        dt.Columns.Add("Remainder", typeof(string));
                    }

                    payments = term * 12;

                    for (int i = 1; i <= payments; i++)
                    {
                        double collateral;

                        collateral = loan.CalculatePayment() - loan.CalculateInterest(remainder);
                        remainder -= collateral;

                        DataRow newRow = dt.NewRow();

                        newRow[0] = i.ToString();
                        newRow[1] = collateral;
                        newRow[2] = loan.CalculateInterest(remainder);
                        newRow[3] = remainder;

                        dt.Rows.Add(newRow);
                    }

                    grdLoanData.DataSource = dt;
                    grdLoanData.DataBind();
                }
                else
                {
                    lblMessage.Text = "Set a numeric term.";
                }
            }
            else
            {
                lblMessage.Text = "Set a numeric amount.";
            }
        }
Exemplo n.º 2
0
        public static void Main()
        {
            Loan individualLoad = new Loan()
            {
                Balance             = 1505.20m,
                Customer            = new Individual(),
                MonthlyInterestRate = 12.3m
            };

            var individualLoanInterestForSixMonths = individualLoad.CalculateInterest(new IndividualLoanProvider(), 6);

            Console.WriteLine("12.3 * 6 = " + 12.3m * 6);
            Console.WriteLine("12.3 * (6-3) = " + individualLoanInterestForSixMonths);

            Mortgage individualMortgage = new Mortgage()
            {
                Balance             = 123.123m,
                Customer            = new Individual(),
                MonthlyInterestRate = 9.5m
            };

            var individualMortgageInterestForEightMonths = individualMortgage.CalculateInterest(new IndividualMortgageProvider(), 8);

            Console.WriteLine("9.5 * 8 = " + 9.5m * 8);
            Console.WriteLine("9.5 * (8-6) = " + individualMortgageInterestForEightMonths);
        }
Exemplo n.º 3
0
    static void Main()
    {
        Deposit deposit = new Deposit(new Individual("Phili Fry"), 5000m, 5);
        deposit.DepositIn(1000m);
        Console.WriteLine(deposit.Balance);
        deposit.Withdraw(1500m);
        Console.WriteLine(deposit.Balance);
        Console.WriteLine(deposit.CalculateInterest(5));

        Console.WriteLine("-------------------");

        Loan loan = new Loan(new Individual("James"), 2000m, 20);
        loan.DepositIn(2000m);
        Console.WriteLine(loan.Balance);
        Console.WriteLine(loan.CalculateInterest(5));

        Console.WriteLine("-------------------");

        Loan companyLoan = new Loan(new Company("Telecom"), 2000m, 20);
        companyLoan.DepositIn(3000m);
        Console.WriteLine(companyLoan.Balance);
        Console.WriteLine(companyLoan.CalculateInterest(5));

        Console.WriteLine("-------------------");

        Mortgage mortgage = new Mortgage(new Individual("Bart"), 2000m, 20);
        mortgage.DepositIn(3000m);
        Console.WriteLine(mortgage.Balance);
        Console.WriteLine(mortgage.CalculateInterest(8));

        Console.WriteLine("-------------------");

        Mortgage companyMortgate = new Mortgage(new Company("Airline"), 2000m, 20);
        Console.WriteLine(companyMortgate.CalculateInterest(16));
    }
 static void Main()
 {
     Console.WriteLine("Enter number");
     int number = int.Parse(Console.ReadLine());
     try
     {
         for (int count = 0; count < number; count++)
         {
             Console.WriteLine("Enter customer kind");               //true equals to individual, and false to company
             bool customerKind = bool.Parse(Console.ReadLine());
             Console.WriteLine("Enter customer name");
             string customerName = Console.ReadLine();
             Customer customer = new Customer(customerKind, customerName);
             Console.WriteLine("Enter interest rate");
             float currentInterestRate = float.Parse(Console.ReadLine());
             Console.WriteLine("Enter account balance");
             double currentBalance = double.Parse(Console.ReadLine());
             Deposit deposit = new Deposit(customer, currentInterestRate, currentBalance);
             Loan loan = new Loan(customer, currentInterestRate, currentBalance);
             Mortgage mortgage = new Mortgage(customer, currentInterestRate, currentBalance);
             Console.WriteLine("Enter start month");
             byte startMonth = byte.Parse(Console.ReadLine());
             Console.WriteLine("Enter end month");
             byte endMonth = byte.Parse(Console.ReadLine());
             Console.WriteLine("Interest for the deposit is {0}", deposit.CalculateInterest(startMonth, endMonth));
             Console.WriteLine("Interest for the loan is {0}", loan.CalculateInterest(startMonth, endMonth));
             Console.WriteLine("Interest for the morgage is {0}", mortgage.CalculateInterest(startMonth, endMonth));
         }
     }
     catch (ArgumentException ae)
     {
         Console.WriteLine(ae.Message);
     }
 }
        public void CreateLoan_AddMinus5Interest_ShouldThrowExceptionWithMessage()
        {
            Loan loan = new Loan();

            ArgumentException ae = Assert.ThrowsException <ArgumentException>(() => loan.CalculateInterest(-0.05));

            Assert.AreEqual("Interest rate should be a positive double value", ae.Message);
        }
        public void CreateLoan_Add5Interest_AmountShouldBe1050()
        {
            Loan loan = new Loan();

            loan.CalculateInterest(0.05);

            Assert.AreEqual(1050, loan.Amount);
        }
        public void CreateLoan_AddInterest_ShouldBe_UsingDynamicData(double initialAmount, double interestRate, double newAmount)
        {
            // Arrange
            Loan loan = new Loan(initialAmount);

            // Act
            loan.CalculateInterest(interestRate);

            // Assert
            Assert.AreEqual(newAmount, loan.Amount);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Deposit deposit = new Deposit(new Individual("me", 123), 499, 0.1m, 2);

            Console.WriteLine(deposit.InterestRate);
            deposit.Deposit(10);
            Console.WriteLine(deposit.Balance);
            Loan myLoan = new Loan(new Company("MT", 11), 1000, 0.3m, 2);

            Console.WriteLine(myLoan.CalculateInterest());
            var morgage = new Mortgage(new Individual("me again", 1), 1000, 0.1m, 7);

            Console.WriteLine(morgage.CalculateInterest());
            morgage = new Mortgage(new Company("me ET", 1), 2000, 0.4m, 7);
            Console.WriteLine(morgage.CalculateInterest());
        }
Exemplo n.º 9
0
 public static void Main()
 {
     CompanyCustomer company = new CompanyCustomer("Company");
     IndividualCustomer pesho = new IndividualCustomer("Pesho");
     IndividualCustomer ivan = new IndividualCustomer("Ivan");
     IAccount peshoLoan = new Loan(pesho, 2500, 6.5m);
     IAccount companyMortgage = new Mortgage(company, 15000, 8.8m);
     IAccount ivanDeposit = new Deposit(ivan, 8000, 3.5m);
     List<IAccount> myAccounts = new List<IAccount>{peshoLoan, companyMortgage, ivanDeposit};
     Bank bigBank = new Bank(myAccounts);
     Console.WriteLine();
     bigBank.ListAllAccounts();
     Console.WriteLine();
     bigBank.InterestForAll(12);
     Console.WriteLine("\nPesho's interest for 30 months: {0}", peshoLoan.CalculateInterest(30));
     Console.WriteLine();
 }
Exemplo n.º 10
0
        public static void Main()
        {
            Console.Title = "Problem 2.	Bank of Kurtovo Konare";

            Deposit goshoDeposit = new Deposit(Customer.Individuals, 1000m, 0.05m);
            goshoDeposit.DepositMoney(450);
            goshoDeposit.WithdrawMoney(400);
            Console.WriteLine(goshoDeposit + "Interest = " + goshoDeposit.CalculateInterest(10));
            Console.WriteLine();

            Loan carskiZaem = new Loan(Customer.Companies, 50000m, 0.1m);
            carskiZaem.DepositMoney(1);
            Console.WriteLine(carskiZaem + "Interest = " + carskiZaem.CalculateInterest(5));
            Console.WriteLine();

            Mortgage bmwPesho = new Mortgage(Customer.Individuals, 10000m, 0.01m);
            bmwPesho.DepositMoney(5000);
            Console.WriteLine(bmwPesho + "Interest = " + bmwPesho.CalculateInterest(30));
        }
Exemplo n.º 11
0
        static void Main()
        {
            try
            {
                Deposit deposit = new Deposit(Customer.Company, 20000m, 3.4m);
                deposit.Withdraw(345m);
                deposit.DepositMoney(1000m);
                deposit.CalculateInterest(10);
                Console.WriteLine("Deposit:\n{0}", deposit);

                Loan loanIndividual = new Loan(Customer.Individual, 1000m, 20m);
                loanIndividual.DepositMoney(3000m);
                loanIndividual.CalculateInterest(5);
                Console.WriteLine("Loan individual:\n{0}", loanIndividual);

                Loan loanCompalny = new Loan(Customer.Company, 200000m, 5m);
                loanCompalny.DepositMoney(30000m);
                loanCompalny.CalculateInterest(4);
                Console.WriteLine("Loan company:\n{0}", loanCompalny);

                Mortage mortageIndividual = new Mortage(Customer.Individual, 500, 3.3m);
                mortageIndividual.DepositMoney(200m);
                mortageIndividual.CalculateInterest(7);
                Console.WriteLine("Mortage individual:\n{0}", mortageIndividual);

                Mortage mortageCompany = new Mortage(Customer.Company, 50000, 4m);
                mortageIndividual.DepositMoney(2000m);
                mortageIndividual.CalculateInterest(13);
                Console.WriteLine("Mortage individual:\n{0}", mortageIndividual);
            }
            catch (OverflowException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            try
            {
                Deposit deposit = new Deposit(Customer.Company, 20000m, 3.4m);
                deposit.Withdraw(345m);
                deposit.DepositMoney(1000m);
                deposit.CalculateInterest(10);
                Console.WriteLine("Deposit:\n{0}", deposit);

                Loan loanIndividual = new Loan(Customer.Individual, 1000m, 20m);
                loanIndividual.DepositMoney(3000m);
                loanIndividual.CalculateInterest(5);
                Console.WriteLine("Loan individual:\n{0}", loanIndividual);

                Loan loanCompalny = new Loan(Customer.Company, 200000m, 5m);
                loanCompalny.DepositMoney(30000m);
                loanCompalny.CalculateInterest(4);
                Console.WriteLine("Loan company:\n{0}", loanCompalny);

                Mortage mortageIndividual = new Mortage(Customer.Individual, 500, 3.3m);
                mortageIndividual.DepositMoney(200m);
                mortageIndividual.CalculateInterest(7);
                Console.WriteLine("Mortage individual:\n{0}", mortageIndividual);

                Mortage mortageCompany = new Mortage(Customer.Company, 50000, 4m);
                mortageIndividual.DepositMoney(2000m);
                mortageIndividual.CalculateInterest(13);
                Console.WriteLine("Mortage individual:\n{0}", mortageIndividual);
            }
            catch (OverflowException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public void CreateLoan_AddMinus5Interest_ShouldThrowException()
        {
            Loan loan = new Loan();

            Assert.ThrowsException <ArgumentException>(() => loan.CalculateInterest(-0.05));
        }
Exemplo n.º 14
0
 static void Main()
 {
     var loan = new Loan(new Individuals("Pesho"), 2000, 0.29m);
     loan.CalculateInterest(4);
 }
Exemplo n.º 15
0
    static void Main()
    {
        // Innstance of an individual and a Company customer
        Customer cust1 = new Individual("Misho", "Sofia", "541010");
        Customer cust2 = new Company("Albireo", "Plovdiv", "BG1211121121");

        // Deposit account-Individual customer
        Deposit account01 = new Deposit(cust1, 0.5);
        Console.WriteLine("Open new deposit for Individual. Starting ammount ->{0}", account01.Balance);
        account01.DepositMoney(1500);
        Console.WriteLine("Deposit 1500. Ammount ->{0}", account01.Balance);
        account01.WithdrawMoney(400);
        Console.WriteLine("Withdraw 400. Ammount ->{0}", account01.Balance);

        account01.CalculateInterest(5);
        Console.WriteLine("Calculate interest of {1}% for 5 months. Ammount ->{0}", account01.Balance, account01.InterestRate);
        account01.WithdrawMoney(600);
        Console.WriteLine("Withdraw 600. Ammount ->{0}", account01.Balance);
        account01.CalculateInterest(3);

        // 0% interest when balance is below 1000
        Console.WriteLine("Calculate interest of {1}% for 3 months. Ammount ->{0}", account01.Balance, account01.InterestRate);
        Console.WriteLine();

        //Loan account - Company
        Loan account02 = new Loan(cust2, 11000, 1);
        Console.WriteLine("Open new loan for a company. Ammount -> {0}", account02.Balance);
        account02.DepositMoney(3000);
        Console.WriteLine("Deposit 3000. Ammount -> {0}", account02.Balance);
        account02.CalculateInterest(2);
        // 0% interest or the first 2 months
        Console.WriteLine("Calculate interest of {1}% for 2 months. Ammount ->{0}", account02.Balance, account02.InterestRate);
        account02.CalculateInterest(5);
        Console.WriteLine("Calculate interest of {1}% for 5 months. Ammount ->{0}", account02.Balance, account02.InterestRate);
        Console.WriteLine();

        //Loan Account - Individual
        Loan account03 = new Loan(cust1, 1000, 1.2);
        Console.WriteLine("Open new loan for an individual. Ammount -> {0}", account03.Balance);
        account03.DepositMoney(100);
        Console.WriteLine("Deposit 100. Ammount -> {0}", account03.Balance);
        // 0% interest or the first 3 months
        account03.CalculateInterest(3);
        Console.WriteLine("Calculate interest of {1}% for 3 months. Ammount ->{0}", account03.Balance, account03.InterestRate);
        account03.CalculateInterest(5);
        Console.WriteLine("Calculate interest of {1}% for 5 months. Ammount ->{0}", account03.Balance, account03.InterestRate);
        Console.WriteLine();

        //Mortgage account - Individual
        Mortgage account04 = new Mortgage(cust1, 50000, 0.6);
        Console.WriteLine("Open new mortgage for an individual. Ammount -> {0}", account04.Balance);
        // 0% interest or the first 6 months
        account04.CalculateInterest(6);
        Console.WriteLine("Calculate interest of {1}% for 6 months. Ammount ->{0}", account04.Balance, account04.InterestRate);
        account04.CalculateInterest(7);
        Console.WriteLine("Calculate interest of {1}% for 7 months. Ammount ->{0}", account04.Balance, account04.InterestRate);
        account04.DepositMoney(1500);
        Console.WriteLine("Deposit 1500. Ammount -> {0}", account04.Balance);
        Console.WriteLine();

        // Mortgage account - Company
        Mortgage account05 = new Mortgage(cust2, 500000, 0.4);
        Console.WriteLine("Open new mortgage for a company. Ammount -> {0}", account05.Balance);
        account05.CalculateInterest(10);
        Console.WriteLine("Calculate interest of {1}% for 10 months. Ammount ->{0}", account05.Balance, account05.InterestRate);
        account05.CalculateInterest(15);
        Console.WriteLine("Calculate interest of {1}% for 15 months. Ammount ->{0}", account05.Balance, account05.InterestRate);
        account05.DepositMoney(5000);
        Console.WriteLine("Deposit 5000. Ammount -> {0}", account05.Balance);
    }