Using Visual Basics, write a program: When $1000 is invested at 5 % simple inter
ID: 3690600 • Letter: U
Question
Using Visual Basics, write a program: When $1000 is invested at 5 % simple interest, the amount grows by $50 each year. When money is invested at 5 % interest compounded annually, the amount at the end of each year is 1.05 times the amount at the beginning of that year. Display the amounts for 9 years for a $1000 investment at 5 % simple and compound interest.
This is what i have no far...
Private Sub BtnDisplay_Click(sender As Object, e As EventArgs) Handles BtnDisplay.Click
Dim AmountCompound As Double = 1000 * 1.05
Dim AmountSimple As Double = 1000 + 50
Dim Year As Integer
Year += 1
For Year = 1 To 10
lstInterest.Items.Add("" & " " & " Simple Interest " & " " & "Compound Interest")
lstInterest.Items.Add(CStr(Year) & " " & AmountSimple & " " & AmountCompound)
AmountSimple += 50
AmountCompound = AmountCompound * 1.05
Next
End Sub
End Class
Explanation / Answer
Bellow code is using ListView:
Note: i think your code is not dispaly correctly
Private Sub BtnDisplay_Click(sender As Object, e As EventArgs) Handles BtnDisplay.Click
Dim AmountCompound As Double = 1000 * 1.05
Dim AmountSimple As Double = 1000 + 50
Dim Year As Integer
''Set view property
lstInterest.View = View.Details
lstInterest.GridLines = True
lstInterest.FullRowSelect = True
'Add column header
lstInterest.Columns.Add("YEAR", 80)
lstInterest.Columns.Add("SIMPLE INTEREST ", 120)
lstInterest.Columns.Add("COMPOUND INTEREST", 135)
'Add items in the listview
Dim arr(3) As String
Dim itm As ListViewItem
Year += 1
For Year = 1 To 10
'Add items
arr(0) = CStr(Year)
arr(1) = "$" & [String].Format("{0:0,0.00}", AmountSimple)
arr(2) = "$" & [String].Format("{0:0,0.00}", AmountCompound)
itm = New ListViewItem(arr)
lstInterest.Items.Add(itm)
'ListView1.Items.Add(CStr(Year) & " " & AmountSimple & " " & AmountCompound)
AmountSimple += 50
AmountCompound = AmountCompound * 1.05
Next
End Sub
Below code is using gridview control this is the another way:
Private Sub BtnDisplay_Click(sender As Object, e As EventArgs) Handles BtnDisplay.Click
Dim myList As New List(Of MyObject)()
Dim AmountCompound As Double = 1000 * 1.05
Dim AmountSimple As Double = 1000 + 50
Dim Year As Integer
Year += 1
For Year = 1 To 10
myList.Add(New MyObject(CStr(Year), "$" & [String].Format("{0:0,0.00}", AmountSimple), "$" & [String].Format("{0:0,0.00}", AmountCompound)))
AmountSimple += 50
AmountCompound = AmountCompound * 1.05
Next
DataGridView1.DataSource = myList
End Sub
Public Class MyObject
Public Sub New(YEAR As Integer, SIMPLEINTEREST As String, COMPOUNDINTEREST As String)
_YEAR = YEAR
_SIMPLEINTEREST = SIMPLEINTEREST
_COMPOUNDINTEREST = COMPOUNDINTEREST
End Sub
Private _YEAR As Integer
Public Property YEAR() As Integer
Get
Return _YEAR
End Get
Set(value As Integer)
_YEAR = value
End Set
End Property
Private _SIMPLEINTEREST As String
Public Property SIMPLEINTEREST() As String
Get
Return _SIMPLEINTEREST
End Get
Set(value As String)
_SIMPLEINTEREST = value
End Set
End Property
Private _COMPOUNDINTEREST As String
Public Property COMPOUNDINTEREST() As String
Get
Return _COMPOUNDINTEREST
End Get
Set(value As String)
_COMPOUNDINTEREST = value
End Set
End Property
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.