Ejemplo n.º 1
0
        public List <Payment> CalculatePayments(BaseLoan loan)
        {
            _loan = loan;

            List <Payment> payments = new List <Payment>();

            double amountLeft = _loan.LoanAmount;
            double principal  = amountLeft / _loan.LoanTermInMonths;
            double monthlyInterest;
            double payment;

            for (int currentMonth = 1; currentMonth <= _loan.LoanTermInMonths; currentMonth++)
            {
                monthlyInterest = (amountLeft * _loan.Interest) / 12;

                amountLeft = (currentMonth != _loan.LoanTermInMonths) ? amountLeft - principal : 0;

                payment = principal + monthlyInterest;

                Payment paymentToAdd = _paymentFactory.Create(
                    DateTime.Now.AddMonths(currentMonth),
                    payment,
                    principal,
                    monthlyInterest,
                    amountLeft
                    );

                payments.Add(paymentToAdd);
            }

            return(payments);
        }
        public List <Payment> CalculatePayments(BaseLoan loan)
        {
            _loan = loan;

            List <Payment> payments = new List <Payment>();

            double monthlyInterest;
            double principal;
            double amountLeft = _loan.LoanAmount;
            double payment    = calculateMonthlyPayment();

            for (int currentMonth = 1; currentMonth <= _loan.LoanTermInMonths; currentMonth++)
            {
                monthlyInterest = _loan.Interest / 12 * amountLeft;

                if (currentMonth != _loan.LoanTermInMonths)
                {
                    principal = payment - monthlyInterest;
                }
                else
                {
                    principal = amountLeft;
                    payment   = amountLeft + monthlyInterest;
                }

                amountLeft -= principal;

                Payment paymentToAdd = _paymentFactory.Create(
                    DateTime.Now.AddMonths(currentMonth),
                    payment,
                    principal,
                    monthlyInterest,
                    amountLeft
                    );

                payments.Add(paymentToAdd);
            }
            return(payments);
        }