Need tutor

Posted on 2004-11-17
Last Modified: 2012-06-22
I need a tutor to help me with a program for a class project.  I am at stuck at step 9 in the instructions.  If possible, Program Sharing in MSN Messenger would be most efficient, but if you have a way to talk me through this in the forum that will be okay also.  I have a couple of open questions about this project in this EE category already, and I will award points from those open question to whomever can help me get this app running as specified below.

Here is what my app currently looks like:

1.) Write a VB.NET program using a graphical user interface
2.) Calculates and display the mortgage payment amount from user input of the amount of the mortgage, the term of the
mortgage, and the interest rate of the mortgage.  
3.) Allow the user to loop back and enter new data or quit.  
4.) Modify the mortgage program to allow the user to input the amount of a mortgage and then select from a menu of mortgage loans: 7 year at 5.35%, 15 year at 5.5 %, and 30 year at 5.75%.  
5.) Use an array for the different loans.  
6.) Display the mortgage payment amount.  
7.) Then, list the loan balance and interest paid for each payment over the term of the loan.  
8.) Allow the user to loop back and enter a new amount and make a new selection, or quit.  
9.) Modify the mortgage program to allow the user to select which way they want to calculate a mortgage: by input of the
amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage payment (as was done in the Step 2) or by input of the amount of a mortgage and then select from a menu of mortgage loans: 7 year at 5.35%, 15 year
at 5.5 %, and 30 year at 5.75% (as was done in Step 3).  
10.) In either case, display the mortgage payment amount.  
11.) Then, list the loan balance and interest paid for each payment over the term of the loan.  
12.) Allow the user to loop back and enter a new amount and make a new selection, or quit.  
13.) Load the interest rates for the 7 year, 15 year, and 30 year loans from a file.
Question by:gmahler5th
    LVL 96

    Expert Comment

    by:Bob Learned
    Look at a combination RadioButtons and TextBoxes.


    Author Comment

    I understand what you are saying Bob, but I don't know how to tie all the logic together once I get the radio buttons on the page.  
    LVL 96

    Expert Comment

    by:Bob Learned
    Have you added the RadioButtons, such as:

    Calculation method:
    ( ) By amount, term, and interest rate
    ( ) By amount and selected loan


    Author Comment

    No i was thinking i would use tabs to allow the user to select which method to calculate the loan.  I guess you are suggesting radio buttons would be easier?
    LVL 96

    Expert Comment

    by:Bob Learned
    I am not a big fan of tabs--they hide functionality.  Although, tabs start to make sense when there are a lot of controls, but if that is true, then I try to evaluate why there are so many and redistribute to different forms.  It's all about personal preference, though.  While learning something new, you should experiment with it both ways and see which way you like best.  Just because I feel one way doesn't mean that you have to.


    Author Comment

    Actually I'm stuck at step 4.  

    I can't quite visualize the UI if I keep it all on the same form using radio buttons.

    Can you provide any suggestions?

    Author Comment

    Okay I finally have a UI that meets the requirements. (Step 4 and Step 9)

    Now I need to build in the logic to display the payment for steps 5/6/10.  My form code can be seen at the following URL

    Can someone please help me with the code for steps 5, 6, 10, 11 and 13?
    LVL 96

    Expert Comment

    by:Bob Learned
    Second lesson:

    Learn early that code in the form control's event sink is generally poor practice.  Put that code in a class (Study the Model-View-Controller pattern).

    Third lesson:

    Create a method that will calculate the mortgage based on parameters defined from the form so that you set up.


    Author Comment

    I am stuck on steps 9 and 13 now.  Alllowing the user to choose which calculation method they want to use... and using an array to calculate from predefined rates... and loading the predefined rates from a file...

    Someone please help?
    LVL 6

    Accepted Solution

       'declare your variables here
        Dim iRates As New Rates

        Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
            Dim Fmt As String
            Dim TotPmts As Integer
            Dim PVal, APR, FVal, Payment, dblMonth, dblRateMonth As Double

            'assign the values from textboxes to the variables
            If CT1.Checked = True Then ' Choose own rates
                APR = Convert.ToDouble(txtRate.Text)
                TotPmts = Convert.ToInt32(txtYears.Text)
            ElseIf CT2.Checked = True Then ' Predefined
                If PDR1.Checked = True Then
                    APR = iRates.Item(0).Num2
                    TotPmts = Convert.ToInt32(iRates.Item(0).Num1)
                ElseIf PDR2.Checked = True Then
                    APR = iRates.Item(1).Num2
                    TotPmts = Convert.ToInt32(iRates.Item(1).Num1)
                ElseIf PDR3.Checked = True Then
                    APR = iRates.Item(2).Num2
                    TotPmts = Convert.ToInt32(iRates.Item(2).Num1)
                End If
            End If

            PVal = Convert.ToDouble(txtPrincipal.Text)
            TotPmts = TotPmts * 12

            If APR > 1 Then APR = APR / 100 ' Ensure proper form.
            dblMonth = TotPmts * 12
            dblRateMonth = APR / 12

            'calculate the final amount as principal + interest
            Fmt = "###,###,##0.00"   ' Define money format.
            FVal = 0   ' Usually 0 for a loan.
            Payment = PVal / ((1 - (1 + dblRateMonth) ^ -dblMonth) / dblRateMonth)

            'put the calculated amount in Payment Amount textbox
            txtAmount.Text = FormatNumber(Payment, 2, TriState.True, TriState.True, TriState.False)


            Dim objDT As New DataTable
            objDT.Columns.Add("Month", GetType(Integer))
            objDT.Columns.Add("Balance", GetType(Double))
            objDT.Columns.Add("Installment", GetType(Double))
            objDT.Columns.Add("Interest Paid", GetType(Double))
            objDT.Columns.Add("Principal Paid", GetType(Double))

            MyBase.Height = 536

            Dim balanceLeft As Double = PVal '- downPayment
            Dim interestPaid As Double
            Dim LoanDuration As Integer = TotPmts '* 12

            For i As Integer = 1 To LoanDuration
                Dim strRow(4) As Object

                interestPaid = balanceLeft * APR / 100 / 12
                balanceLeft = balanceLeft + interestPaid - Payment

                strRow(0) = i
                strRow(1) = Convert.ToDouble(FormatNumber(balanceLeft, 2))
                strRow(2) = Convert.ToDouble(FormatNumber(Payment, 2))
                strRow(3) = Convert.ToDouble(FormatNumber(interestPaid, 2))
                strRow(4) = Convert.ToDouble(FormatNumber(interestPaid - Payment, 2))

                'al.Add(New repayment(i, balanceLeft, monthlyInstallment, interestPaid, interestPaid - monthlyInstallment))


            Me.dgAmortization.DataSource = objDT
        End Sub

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim oFile As System.IO.File
            Dim oRead As System.IO.StreamReader
            Dim strLine As String
            Dim isEnd As Boolean = False
            Dim strRegExp As String = "PDR(?:\[|\()(?<Seq>\d{1})(?:\]|\))\s\((?<Num1>\d+)(?:,|\.)(?<Num2>[0-9\.]+)\)"

            oRead = oFile.OpenText("C:\rates.txt")
            Do While isEnd = False
                If oRead.Peek = -1 Then
                    isEnd = True
                    Exit Do
                End If
                strLine = oRead.ReadLine

                Dim iMatch As Match = Regex.Match(strLine, strRegExp)

                'MsgBox(iMatch.Groups("").Value.ToString & ":" & iMatch.Groups(1).Value.ToString & ":" & iMatch.Groups(2).Value.ToString)
                Dim seq As Integer = Convert.ToInt32(iMatch.Groups("Seq").Value.ToString)
                Dim num1 As Double = Convert.ToInt32(iMatch.Groups("Num1").Value.ToString)
                Dim num2 As Double = Convert.ToDouble(iMatch.Groups("Num2").Value)

                Dim iRate As New Rate(seq, num1, num2)
                Select Case seq
                    Case 0
                        Me.PDR1.Text = num1 & " Years " & num2 & "%"
                    Case 1
                        Me.PDR2.Text = num1 & " Years " & num2 & "%"
                    Case 2
                        Me.PDR3.Text = num1 & " Years " & num2 & "%"
                End Select
        End Sub

        Public Class Rates
            Inherits CollectionBase

            Public Sub add(ByVal r As Rate)
            End Sub

            Public Overloads Function Item(ByVal Index As Integer) As Rate
                ' To retrieve an item from the InnerList, pass the index of that item to the .Item property.
                Return CType(Me.InnerList.Item(Index), Rate)
            End Function

            Public Overloads Sub Remove(ByVal Index As Integer)
                ' This Remove expects an index.
                Dim iRate As Rate
                iRate = CType(Me.InnerList.Item(Index), Rate)
                If Not iRate Is Nothing Then
                End If
            End Sub
        End Class

        Public Class Rate
            Public Seq As Integer
            Public Num1 As Double
            Public Num2 As Double

            Public Sub New(ByVal oseq As Integer, ByVal onum1 As Double, ByVal onum2 As Double)
                Me.Seq = oseq
                Me.Num1 = onum1
                Me.Num2 = onum2
            End Sub
        End Class
    End Class

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now