Write a program to calculate the balance and minimum payment
Write a program to calculate the balance and minimum payment for a credit card statement. the program should use the event procedure shown in fig 5.31. 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.
Private Sub btnCalculate_Click(...) Handles btnCalculate.Click
Dim oldBalance, charges, credits, newBalance, minPayment As Decimal
InputData (oldBalance, charges, credits)
CalculateNewValues (oldBalance, charges, credits, newBalance, minPayment)
DisplayData (newBalance, minPayment)
End Sub
Solution
Public Class Form1 Private Sub btnCompute_Click(sender As Object, e As EventArgs) Handles btnCompute.Click Dim oldBalance, charges, credits, newBalance, minPayment As Double InputData(oldBalance, charges, credits) CalculateNewValues(oldBalance, charges, credits, newBalance, minPayment) DisplayData(newBalance, minPayment) End Sub Sub InputData(ByRef oldBalance As String, ByRef charges As String, ByRef credits As String) oldBalance = CDbl(txtOldBal.Text) charges = CDbl(txtCharges.Text) credits = CDbl(txtCredits.Text) End Sub Sub CalculateNewValues(ByRef oldBalance As Double, ByRef charges As Double, ByRef credits As Double, ByRef newBalance As Double, ByRef minPayment As Double) Dim rate As Double = 1.015 newBalance = (rate * oldBalance) + charges - credits If newBalance <= 20 Then minPayment = newBalance Else minPayment = ((newBalance - 20) * 0.1) + 20 End If End Sub Sub DisplayData(newBalance As Double, minPayment As Double) lblMinPay.Text = minPayment.ToString(\"C\") lblNewBal.Text = newBalance.ToString(\"C\") End Sub End Class