Calculate the amount of loan payments through user supplied APR, term, and amount.
NOTE: Mathematical calculations are not correct.
'Document Properties 'Author: G. Andrew Bowman 'Version: 2005.09.28 'Objective: Calculates monthly payment to uses based upon amount, term, and percentage. 'Purpose: This is the startup page for the user. Module init Sub Main() 'Declare Classes Dim myloan As New verifData Dim header As New header 'Display Header header.display() 'Get Datum from user using "verifData.vb" myloan.testAmount() header.display() myloan.testInterest() header.display() myloan.testTerm() header.display() 'Display the data to the user Console.WriteLine("Prinicipal Amount: {0:C}", myloan.recallAmount()) Console.WriteLine("APR: " & myloan.recallInterest() & "%") Console.WriteLine("Term: " & myloan.recallTerm() & " year(s)") Console.WriteLine("Monthly Payment: {0:C}", myloan.monthlyPayment()) Console.WriteLine("Monthly Interest: {0:C}", myloan.interestMonthly()) 'Exit the program Console.WriteLine(vbCrLf & vbCrLf & vbCrLf) Console.Write("---------------------------------------------------------" & vbCrLf) Console.Write(" Press any key to terminate program " & vbCrLf) Console.ReadKey() End Sub End Module
'Document Properties 'Author: G. Andrew Bowman 'Version: 2005.09.28 'Purpose: Clears the screen and displays the default header for the program Public Class header Public Function display() As Integer 'Clear the screen Console.Clear() 'Display the user header Console.Write("---------------------------------------------------------" & vbCrLf) Console.Write("--------- Visual Basic Loan Program ---------" & vbCrLf) Console.Write("------------ Version 2005.09.28 -------------" & vbCrLf) Console.Write("------------- G. Andrew Bowman --------------" & vbCrLf) Console.Write("---------------------------------------------------------" & vbCrLf & vbCrLf & vbCrLf & vbCrLf) End Function End Class
'Document Properties 'Author: G. Andrew Bowman 'Version: 2005.09.28 'Purpose: Verifies data entered by user for amount, interest, and data Public Class verifData 'Declare Variables Private mAmount As Integer Private mInterest As Integer Private mTerm As Integer Private displayPayment As Integer 'Validate the amount value Public Function testAmount() As Integer 'check range mAmount = 0 Do While (mAmount <= 0) Or (mAmount > 200000) Console.WriteLine("Please enter the amount of your loan ($1 to $20,000).") Console.Write(" Loan Amount: $") mAmount = Console.ReadLine() Loop End Function 'Validate the interest value Public Function testInterest() As Integer 'check range mInterest = 0 Do While (mInterest < 1) Or (mInterest > 20) Console.WriteLine("Please enter the Annual Percentage Rate (1.0% to 20.0%).") Console.Write(" Percentage Rate: ") mInterest = Console.ReadLine() Loop End Function 'Validate the term value Public Function testTerm() As Integer mTerm = 0 Do While (mTerm <= 0) Or (mTerm > 30) Console.WriteLine("Please enter the term of the loan (1 to 30 years).") Console.Write(" Term: ") mTerm = Console.ReadLine() Loop End Function 'Calculate the monthly payment Public Function monthlyPayment() As Decimal Dim monthlyInt As Decimal = (mInterest / 12) Dim numPay As Integer = (mTerm * 12) Return (mAmount * (monthlyInt * (1 + monthlyInt) ^ numPay)) / (((1 + monthlyInt) ^ numPay) - 1) End Function 'Calculate the monthly interest Public Function interestMonthly() As Decimal Dim yearlyPay as Integer = (mAmount * (mInterest * (1 + mInterest) ^ mTerm)) / (((1 + mInterest) ^ mTerm) - 1) Return ((yearlyPay) - (mAmount / mTerm)) / 12 End Function 'Recall the Amount to user Public Function recallAmount() As Decimal Return mAmount End Function 'Recall the Interest to user Public Function recallInterest() As Decimal Return mInterest End Function 'Recall the Term to user Public Function recallTerm() As Decimal Return mTerm End Function End Class