示例#1
0
        /// <summary>
        /// Get a resulting loan object
        /// </summary>
        /// <param name="concreteLoanInput"></param>
        /// <returns></returns>
        private ConcreteLoanOutput GetLoanOutput(ConcreteLoanInput concreteLoanInput)
        {
            var loanAmount       = Convert.ToDouble(concreteLoanInput.Amount - concreteLoanInput.Downpayment);
            var rateOfInterest   = concreteLoanInput.Interest / 1200;
            var numberOfPayments = concreteLoanInput.Term * 12;

            var monthlyPayment = (rateOfInterest * loanAmount) / (1 - Math.Pow(1 + rateOfInterest, numberOfPayments * -1));
            var totalPayment   = monthlyPayment * numberOfPayments;
            var totalInterest  = totalPayment - loanAmount;

            return(new ConcreteLoanOutput()
            {
                MonthlyPayment = decimal.Round(Convert.ToDecimal(monthlyPayment), 2),
                TotalInterest = decimal.Round(Convert.ToDecimal(totalInterest), 2),
                TotalPayment = decimal.Round(Convert.ToDecimal(totalPayment), 2)
            });
        }
示例#2
0
 /// <summary>
 /// sanity check
 /// </summary>
 /// <param name="concreteCalcInput"></param>
 /// <returns></returns>
 private bool IsDataCorrect(ConcreteLoanInput concreteCalcInput) =>
 concreteCalcInput.Amount > 0 &&
 concreteCalcInput.Downpayment >= 0 &&
 concreteCalcInput.Interest > 0 &&
 concreteCalcInput.Term > 0;