public override string ToString() { return($"{Term} months (effective {AnnualPercentageRate}, nominal {NominalRate}): monthly {MonthlyPayment.ToString()}, total {TotalCost.ToString()}, interest {TotalInterest.ToString()}"); }
private void calculateBTN_Click(object sender, EventArgs e) { try { //declaring variables double PurchasePrice, DownPymt, Rate, MonthlyPymt, LoanAmt, Percent, TotalInterest; int Term; //parsing text PurchasePrice = double.Parse(inPurchasePriceTB.Text); DownPymt = double.Parse(inDownPymtTB.Text); Rate = double.Parse(rateTB.Text) / 100; Term = int.Parse(termTB.Text); Percent = double.Parse(inDownPymtTB.Text) / 100; //Checking Percent of purchase price or dollar value if (percentRB.Checked) { DownPymt = PurchasePrice * Percent; } else if (dollarsRB.Checked) { DownPymt = double.Parse(inDownPymtTB.Text); } // checking Years or Months if (yearsRB.Checked) { Term = Term * 12; } else if (monthRB.Checked) { Term = int.Parse(termTB.Text); } // assigning formula variables double interest = Rate / 12; LoanAmt = PurchasePrice - DownPymt; MonthlyPymt = LoanAmt * ((interest * (Math.Pow(1 + interest, Term))) / (Math.Pow(1 + interest, Term) - 1)); TotalInterest = (MonthlyPymt * Term) - LoanAmt; double totalAmtPaid = MonthlyPymt * Term; // Display the answers loanAmtTB.Text = LoanAmt.ToString(); monthlyPymtTB.Text = MonthlyPymt.ToString("n2"); totalInterestPaidTB.Text = TotalInterest.ToString("n2"); totalAmtPaidTB.Text = totalAmtPaid.ToString("n2"); } catch (Exception) { MessageBox.Show("Something is WRONG with your figures"); } }