From \"An Introduction to Programming using Visual Basic 2012\" using Visual Stu
ID: 3684821 • Letter: F
Question
From "An Introduction to Programming using Visual Basic 2012" using Visual Studio and Visual language, I need help with Chapter 5.3 Question 10 called "Credit Card Payment"
"Write a program to calculate the balance and minimum payment for a credit card statement. See Fig 5.27 (attached photo). The program should use the event procedure shown in Fig 5.28 (typed below). The finance charge is 1.5% of the old balance. If the new balance is $20 or less, the minimum payment should be the entire new balance. Otherwise, the minimum payment should be $20 plus 10% of the amount of the new balance above $20.
Fig 5.28:
Private Sub btnCalculate_Click (...) Handles btnCalculate.Click
dim oldBalance, charges, credits, newBalance, minPayment As Double
InputData (oldBalance, charges, credits)
CalculateNewValues (oldBalance, charges, credits, newBalance, minPayment)
DisplayData (newBalance, minPayment)
End Sub
Explanation / Answer
Please Go throught the bellow link and download the zip file and run te application plz let me know your comments.
https://we.tl/8j6uZnWDOY
.cs Code
Imports System.Globalization
Public Class Form1
Dim oldBal As Double, chargeAmount As Double, CriditsAmount As Double, financeCharge As Double, newBalance As Double, newBalPer As Double
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
CalCulateNewBalance()
End Sub
Private Sub CalculateMinBalanace()
If newBalance > 20 Then
newBalPer = newBalance - 20
newBalPer = newBalPer * 10
newBalPer = newBalPer / 100
textMinPayments.Text = "$ " & Addingcomma(newBalPer + 20)
Else
textMinPayments.Text = "$ " & Addingcomma(newBalance)
End If
End Sub
Private Sub CalCulateNewBalance()
If textOldBalance.Text = "" Then
MessageBox.Show("Enter Old Balance")
textOldBalance.Focus()
Return
End If
If textCharges.Text = "" Then
MessageBox.Show("Enter Charges")
textCharges.Focus()
Return
End If
If textCridits.Text = "" Then
MessageBox.Show("Enter Cridits")
textCridits.Focus()
Return
End If
oldBal = Convert.ToDouble(textOldBalance.Text)
chargeAmount = Convert.ToDouble(textCharges.Text)
CriditsAmount = Convert.ToDouble(textCridits.Text)
financeCharge = oldBal * 1.5 / 100
newBalance = financeCharge + chargeAmount + CriditsAmount
textNewBalance.Text = "$ " & Addingcomma(newBalance)
CalculateMinBalanace()
End Sub
Private Shared Function Addingcomma(totaltax As Double) As String
Dim d As Double = totaltax
Dim nfi As NumberFormatInfo = New CultureInfo("en-US", False).NumberFormat
Return totaltax.ToString("N", CultureInfo.InvariantCulture)
End Function
Private Sub textOldBalance_KeyPress(sender As Object, e As KeyPressEventArgs) Handles textOldBalance.KeyPress
If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) AndAlso (e.KeyChar <> "."c) Then
e.Handled = True
End If
' only allow one decimal point
If (e.KeyChar = "."c) AndAlso (TryCast(sender, TextBox).Text.IndexOf("."c) > -1) Then
e.Handled = True
End If
End Sub
Private Sub textCharges_KeyPress(sender As Object, e As KeyPressEventArgs) Handles textCharges.KeyPress
If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) AndAlso (e.KeyChar <> "."c) Then
e.Handled = True
End If
' only allow one decimal point
If (e.KeyChar = "."c) AndAlso (TryCast(sender, TextBox).Text.IndexOf("."c) > -1) Then
e.Handled = True
End If
End Sub
Private Sub textCridits_KeyPress(sender As Object, e As KeyPressEventArgs) Handles textCridits.KeyPress
If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) AndAlso (e.KeyChar <> "."c) Then
e.Handled = True
End If
' only allow one decimal point
If (e.KeyChar = "."c) AndAlso (TryCast(sender, TextBox).Text.IndexOf("."c) > -1) Then
e.Handled = True
End If
End Sub
End Class
form Design code:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.textMinPayments = New System.Windows.Forms.TextBox()
Me.label5 = New System.Windows.Forms.Label()
Me.textNewBalance = New System.Windows.Forms.TextBox()
Me.label4 = New System.Windows.Forms.Label()
Me.btnCalculate = New System.Windows.Forms.Button()
Me.textCridits = New System.Windows.Forms.TextBox()
Me.label3 = New System.Windows.Forms.Label()
Me.textCharges = New System.Windows.Forms.TextBox()
Me.label2 = New System.Windows.Forms.Label()
Me.textOldBalance = New System.Windows.Forms.TextBox()
Me.label1 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'textMinPayments
'
Me.textMinPayments.Location = New System.Drawing.Point(234, 198)
Me.textMinPayments.Name = "textMinPayments"
Me.textMinPayments.ReadOnly = True
Me.textMinPayments.Size = New System.Drawing.Size(100, 20)
Me.textMinPayments.TabIndex = 21
'
'label5
'
Me.label5.AutoSize = True
Me.label5.Location = New System.Drawing.Point(131, 201)
Me.label5.Name = "label5"
Me.label5.Size = New System.Drawing.Size(97, 13)
Me.label5.TabIndex = 20
Me.label5.Text = "Minimum payment :"
'
'textNewBalance
'
Me.textNewBalance.Location = New System.Drawing.Point(234, 172)
Me.textNewBalance.Name = "textNewBalance"
Me.textNewBalance.ReadOnly = True
Me.textNewBalance.Size = New System.Drawing.Size(100, 20)
Me.textNewBalance.TabIndex = 19
'
'label4
'
Me.label4.AutoSize = True
Me.label4.Location = New System.Drawing.Point(154, 175)
Me.label4.Name = "label4"
Me.label4.Size = New System.Drawing.Size(74, 13)
Me.label4.TabIndex = 18
Me.label4.Text = "New Balance:"
'
'btnCalculate
'
Me.btnCalculate.Location = New System.Drawing.Point(106, 129)
Me.btnCalculate.Name = "btnCalculate"
Me.btnCalculate.Size = New System.Drawing.Size(297, 23)
Me.btnCalculate.TabIndex = 17
Me.btnCalculate.Text = "Calculate New Bal. and Min. Payments"
Me.btnCalculate.UseVisualStyleBackColor = True
'
'textCridits
'
Me.textCridits.Location = New System.Drawing.Point(303, 86)
Me.textCridits.Name = "textCridits"
Me.textCridits.Size = New System.Drawing.Size(100, 20)
Me.textCridits.TabIndex = 16
'
'label3
'
Me.label3.AutoSize = True
Me.label3.Location = New System.Drawing.Point(245, 89)
Me.label3.Name = "label3"
Me.label3.Size = New System.Drawing.Size(38, 13)
Me.label3.TabIndex = 15
Me.label3.Text = "Cridits:"
'
'textCharges
'
Me.textCharges.Location = New System.Drawing.Point(106, 85)
Me.textCharges.Name = "textCharges"
Me.textCharges.Size = New System.Drawing.Size(100, 20)
Me.textCharges.TabIndex = 14
'
'label2
'
Me.label2.AutoSize = True
Me.label2.Location = New System.Drawing.Point(51, 92)
Me.label2.Name = "label2"
Me.label2.Size = New System.Drawing.Size(49, 13)
Me.label2.TabIndex = 13
Me.label2.Text = "Charges:"
'
'textOldBalance
'
Me.textOldBalance.Location = New System.Drawing.Point(196, 44)
Me.textOldBalance.Name = "textOldBalance"
Me.textOldBalance.Size = New System.Drawing.Size(100, 20)
Me.textOldBalance.TabIndex = 12
'
'label1
'
Me.label1.AutoSize = True
Me.label1.Location = New System.Drawing.Point(122, 44)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(67, 13)
Me.label1.TabIndex = 11
Me.label1.Text = "Old balance:"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(455, 262)
Me.Controls.Add(Me.textMinPayments)
Me.Controls.Add(Me.label5)
Me.Controls.Add(Me.textNewBalance)
Me.Controls.Add(Me.label4)
Me.Controls.Add(Me.btnCalculate)
Me.Controls.Add(Me.textCridits)
Me.Controls.Add(Me.label3)
Me.Controls.Add(Me.textCharges)
Me.Controls.Add(Me.label2)
Me.Controls.Add(Me.textOldBalance)
Me.Controls.Add(Me.label1)
Me.Name = "Form1"
Me.Text = "Credit Card Payment"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Private WithEvents textMinPayments As System.Windows.Forms.TextBox
Private WithEvents label5 As System.Windows.Forms.Label
Private WithEvents textNewBalance As System.Windows.Forms.TextBox
Private WithEvents label4 As System.Windows.Forms.Label
Private WithEvents btnCalculate As System.Windows.Forms.Button
Private WithEvents textCridits As System.Windows.Forms.TextBox
Private WithEvents label3 As System.Windows.Forms.Label
Private WithEvents textCharges As System.Windows.Forms.TextBox
Private WithEvents label2 As System.Windows.Forms.Label
Private WithEvents textOldBalance As System.Windows.Forms.TextBox
Private WithEvents label1 As System.Windows.Forms.Label
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.