Print Friendly and PDF
(Mortgage Calculator Application) A bank offers mortgages that can be repaid in 5, 10, 15, 20, 25 or 30 years. Write an application that allows a user to enter the price of a house (the amount of the mortgage) and the annual interest rate. When the user clicks a Button, the application displays a table of the mortgage length in years together with the monthly payment,
(Mortgage Calculator Application) A bank offers mortgages that can be repaid in 5 ,10, 15, 20, 25 or 30 years. Write an application that allows a user to enter the price of a house (the amount of the mortgage) and the annual interest rate. When the user clicks a Button, the application displays a table of the mortgage length in years together with the monthly payment.


Mortgage Calculator Application in C#

Solution :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Mortgage_Calculator_Application
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            int intMortgageAmount = 0; // house price
            double dblAnnualRate = 0; // annual interest rate
            double dblMonthlyRate = 0;
            decimal decPayment = 0; // monthly payment amount
            int intYears = 5; // years in mortgage
            int intMonths = 0;
            
            intMortgageAmount = Int32.Parse(txtMortgageAmount.Text);
            dblAnnualRate = Double.Parse(txtRate.Text) / 100;
            // calculate monthly interest rate
            dblMonthlyRate = dblAnnualRate / 12;
            lstResults.Items.Clear();
            lstResults.Items.Add(
            "Mortgage Length (Years)\tMonthly Payment");
            // perform payment calculation and display result for
            // 5, 10, 15, 20, 25 and 30 years
            while (intYears <= 30)
            {
                // convert years to months for the calculation
                intMonths = intYears * 12;
                // perform calculation
                decPayment = (decimal)
                (intMortgageAmount * dblMonthlyRate * 
                Math.Pow(1 + dblMonthlyRate, intMonths) / 
               (Math.Pow(1 + dblMonthlyRate, intMonths)- 1));
               
                lstResults.Items.Add(intYears + "\t\t\t" +
                String.Format("{0:C}", decPayment));
                intYears += 5;
            } 
        } 

    }
    }
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: