Case Projects Loan Calculator Create an application that displays a monthly paym
ID: 3710588 • Letter: C
Question
Case Projects Loan Calculator Create an application that displays a monthly payment on a loan. The application should also display the amount applied to the loan's principal each month and the amount that represents interest. Use the following names for the solution and project, respectively: Loan Solution and Loan Project. Save the solution in the VbReloaded20151Chap07 folder. Change the form file's name to Main Form.vb. The application should use annual interest rates from 2% through 10% in increments of 1%, and use terms from 1 through 30 years. You can use the Financial.PPmt method to calculate the portion of the payment applied to the principal each month. The method's syntax is Financial.PPmt (Rate, Per, NPer, PV). In the syntax, Rate is the interest rate, NPer is the number of payment periods, and PV is the present value of the loan. The Per argument is the payment period for which you want to calculate the portion applied to the principal. The Per argument must be a number from 1 through NPer The method returns the calculated value as a Double number. You can either create your own interface or create the one shown in Figure 7-44; the figure shows a sample run of the application. The combo box that gets the interest rate is the DropDown style. The combo box that gets the term is the DropDownList style. The text box that displays the output has its Multiline and ReadOnly properties set to True and its ScrollBars property set to Vertical Loan Calculator Principal: 120000 Annual interest rate (%): 1erm 0ears): Monthly pament 5572.0 splay Exit Principal and interest Principal Interest A 172.90 173.47 174.05 174.63 175.22 175.80 176.39 176.97 400.00 399.42 398.85 398.27 397.68 397.10 96.51 95.93 Figure 7-44 Sample run of the Loan Calculator applicationExplanation / Answer
Screenshot:
Code:
Public Class frmLoanCalculator
Private Sub frmLoanCalculator_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtPrincipal.Select() 'Puts focus on Principal box on form load
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Dim Response As Integer
Response = MessageBox.Show("Do you really want to exit?", "", 'Exit Prompt
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Response = vbYes Then
Me.Close() 'Closes form if Yes selected from prompt
Else
'Clears controls if No selected from prompt
txtPrincipal.Text = ""
cmbAnnualInterestRaate.Text = ""
cmbTerm.Text = ""
txtMonthlyPayment.Text = ""
End If
End Sub
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
'Calculation Procedure
Dim P As Integer, r As Integer, t As Integer
Dim i As Double
Dim iTerm As Integer, iCtr As Integer
Dim PV As Double
Dim MonthPrincipal As Double
Dim MonthInterest As Double
P = txtPrincipal.Text 'Principal
r = cmbAnnualInterestRaate.SelectedItem 'Rate of Interest
t = cmbTerm.SelectedItem 'Terms
i = Format((P * r / 100 * ((1 + r / 100) ^ t / (((1 + r / 100) ^ t) - 1))) / 12, "0.00") 'Monthly EMI calcuated
txtMonthlyPayment.Text = "$" + i.ToString() 'Print Monthly EMI
iTerm = cmbTerm.Text * 12 'No of Months for Loan Period
txtPrincipalInterest.Text = "Principal" & Space(10) & "Interest" & vbCrLf
PV = P
For iCtr = 1 To iTerm
'Monthly Payment calculated using the Financial.PPmt method
MonthPrincipal = Financial.PPmt(r / 100 / 12, iCtr, iTerm, -PV)
MonthInterest = i - MonthPrincipal
PV = PV - MonthPrincipal
txtPrincipalInterest.Text = txtPrincipalInterest.Text & Format(MonthPrincipal, "#.00") & Space(10) & Format(MonthInterest, "#.00") & vbCrLf
Next
End Sub
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.