static void Main(string[] args) { LoanEntity loan = LoanEntity.NewBuilder() .SetLoanName("Test Loan") .SetPrinciple(20000) .SetCurrentBalance(20000) .SetApr(.006155 * 12) .SetMinuminMonthlyPayment(415.76) .Build(); LoanEntity secondLoan = LoanEntity.NewBuilder() .SetLoanName("Test Loan") .SetPrinciple(5000) .SetCurrentBalance(5000) .SetApr(.006155 * 12) .SetMinuminMonthlyPayment(200) .Build(); Console.WriteLine("Expected length of loan paying minimum : " + new LoanTermCalculator() .GetMonthsUntilPaid(loan) .getMonthsUntilPaidOff()); Dictionary <DateTime, double> payementChanges = new Dictionary <DateTime, double> { //{ DateTime.Now.AddMonths(5), 550.0 } }; AmortizationReportGenerator amortizationReportGenerator = new AmortizationReportGenerator(new LoanTermCalculator(), new DateUtil()); AmortizationReport report = amortizationReportGenerator.GenerateReport(loan, payementChanges); AmortizationReport secondReport = amortizationReportGenerator.GenerateReport(secondLoan, payementChanges); AmortizationReportConsolePrinter printer = new AmortizationReportConsolePrinter(); printer.PrintReport(report); printer.PrintReport(secondReport); SnowBallReportGenerator snowBallReportGenerator = new SnowBallReportGenerator(amortizationReportGenerator, new AmortizationReportEvaluator()); List <LoanEntity> loans = new List <LoanEntity> { loan, secondLoan }; List <AmortizationReport> snowBallReports = snowBallReportGenerator.GenerateReport(loans); foreach (AmortizationReport snowReport in snowBallReports) { printer.PrintReport(snowReport); } }
public List <AmortizationReport> GenerateReport(List <LoanEntity> loans) { List <AmortizationReport> reports = new List <AmortizationReport>(); List <LoanEntity> sortedLoans = loans.OrderBy(x => x.GetCurrentBalance()).ToList(); double accumulatedAdditionalPayment = 0; DateTime previousLoanPayoffDate = DateTime.MinValue; foreach (LoanEntity loan in sortedLoans) { Dictionary <DateTime, double> paymentChanges = new Dictionary <DateTime, double>(); if (previousLoanPayoffDate != DateTime.MinValue) { paymentChanges.Add(previousLoanPayoffDate.AddMonths(1), loan.GetMinimumMonthlyPayment() + accumulatedAdditionalPayment); } AmortizationReport report = AmortizationReportGenerator.GenerateReport(loan, paymentChanges); reports.Add(report); previousLoanPayoffDate = AmortizationReportEvaluator.GetLoanPaidOffDateFromReport(report); accumulatedAdditionalPayment += loan.GetMinimumMonthlyPayment(); } return(reports); }