public string InterestRate;
public double Payment { get; set; }
public double Cost { get; set; }
public double Interest { get; set; }
public Mortgage(string P, string ir, string n, double cp, double c, double i)
public double CalcPayment()
int iLoanAmt = Convert.ToInt32(LoanAmt);
double dblInterestRate = (Convert.ToDouble(InterestRate)/12);
int iLoanTerms = Convert.ToInt32(LoanTerms);
return Payment = iLoanAmt *(dblInterestRate * Math.Pow((1+dblInterestRate),iLoanTerms) / (Math.Pow((1+dblInterestRate),iLoanTerms) - 1));
public double CalcTotalCost()
int iLoanTerms = Convert.ToInt32(LoanTerms);
return Cost = Payment * iLoanTerms;
public double CalcInterest()
return Interest = Cost - Payment;
public string ToStrings()
string gap = "".PadRight(4);
return ((("Monthly Payment: ")+(Payment.ToString("C").PadLeft(4))) + gap +((("Total Cost: ")+Cost.ToString("C").PadLeft(4))) + gap +((("Total Interest: ")+Interest.ToString("C").PadLeft(4))));
public static void Main (string[] args)
Console.Write("Enter princial loan amount= ");
string LoanAmt = Console.ReadLine();
double dblPresentValue1 = 0.0;
if (!double.TryParse(LoanAmt, out dblPresentValue1) || dblPresentValue1 <= 0)
Console.WriteLine("Princial Loan Amount must be positive number!");
Console.Write("Enter annual interest rate (as percentage)= ");
string InterestRate = Console.ReadLine();
double dblPresentValue2 = 0.0;
if (!double.TryParse(InterestRate, out dblPresentValue2) || dblPresentValue2 <= 0)
Console.WriteLine("Rate must be positive number!");
Console.Write("Enter monthly term of loan= ");
string LoanTerms = Console.ReadLine();
double dblPresentValue3 = 0.0;
if (!double.TryParse(LoanTerms, out dblPresentValue3) || dblPresentValue3 <= 0)
Console.WriteLine("Term must be positive number!");
Mortgage mortgage = new Mortgage();
mortgage.LoanAmt = LoanAmt;
mortgage.InterestRate = InterestRate;
mortgage.LoanTerms = LoanTerms;
Console.WriteLine(mortgage.CalcPayment());
Console.WriteLine(mortgage.CalcTotalCost());
Console.WriteLine(mortgage.CalcInterest());
Console.WriteLine(mortgage.ToStrings());