public static decimal MonthlyDue(Loan.LoanType type, string principal, string interest, string term = "0", bool nearestTenth = true) { decimal principalValue, interestValue; int termValue; if (!decimal.TryParse(principal, out principalValue)) { throw new ArgumentException("Invalid principal value"); } if (!decimal.TryParse(interest, out interestValue)) { throw new ArgumentException("Invalid interest value"); } if (type == Loan.LoanType.AmortizedPayment) { if (!int.TryParse(term, out termValue)) { throw new ArgumentException("Invalid term value"); } } else { termValue = 0; } return(MonthlyDue(type, principalValue, interestValue, termValue, nearestTenth)); }
//adds to preexisting Loan values public void AddLoanCost(float thisLoanAmount, Loan.LoanType type) { foreach (Loan x in playerLoans) { if (x.thisLoanType == type) { x.loanAmount += thisLoanAmount; print(x.loanAmount); } } }
public static decimal MonthlyDue(Loan.LoanType type, decimal principal, decimal interest, int term = 0, bool nearestTenth = true) { if (type == Loan.LoanType.AmortizedPayment) { return(LoanCalculator.Amortization(principal, term, interest, nearestTenth)); } else if (type == Loan.LoanType.InterestOnlyPayment) { return(LoanCalculator.PayableInterest(principal, interest, nearestTenth)); } throw new ArgumentException("Unsupported loan type"); }
public Loan Create(Loan.LoanType type) { if (type == Loan.LoanType.AmortizedPayment) { return(AmortizedLoan()); } else if (type == Loan.LoanType.InterestOnlyPayment) { return(PerpetualInterestLoan()); } throw new ArgumentException("Unsupported loan type"); }
private void initializeListFromDatabase() { if (loanList != null) { return; } loanList = new Dictionary <long, Loan>(); string condition; Dictionary <string, object> parameters = new Dictionary <string, object>(); constructCondition(out condition, parameters); string sql = string.Format("SELECT * FROM loans WHERE {0} ORDER BY start_date", condition); DataTable results = this.database.Query(sql, parameters); foreach (DataRow row in results.Rows) { Loan.LoanType type = (Loan.LoanType) int.Parse(row["type"].ToString()); Loan loan; if (type == Loan.LoanType.AmortizedPayment) { loan = new AmortizedLoan(DatabaseFactory.Default); loan.Term = int.Parse(row["term"].ToString()); } else if (type == Loan.LoanType.InterestOnlyPayment) { loan = new PerpetualInterestLoan(DatabaseFactory.Default); } else { throw new ApplicationException("Invalid loan type found in database"); } loan.Account = account; loan.Id = long.Parse(row["id"].ToString()); loan.InterestRate = decimal.Parse(row["interest"].ToString()); loan.Principal = decimal.Parse(row["principal"].ToString()); loan.Remarks = row["remarks"].ToString(); loan.StartDate = DateTime.Parse(row["start_date"].ToString()); loan.TakenDate = DateTime.Parse(row["taken_date"].ToString()); loanList.Add(loan.Id, loan); } }
private void toggleLoanType(Loan.LoanType type) { LoanFactory factory = new LoanFactory(DatabaseFactory.Default); if (type == Loan.LoanType.AmortizedPayment) { int term; bool parseResult = int.TryParse(termInput.Text, out term); term = parseResult ? term : 0; loan = factory.ConvertToAmortizedLoan(this.loan as PerpetualInterestLoan, term); } else if (type == Loan.LoanType.InterestOnlyPayment) { loan = factory.ConvertToPerpetualInterestLoan(this.loan as AmortizedLoan); } else { throw new ArgumentException("Unsupported loan type"); } }