At the President’s Day sale, a customer can bring in a coupon for a 10%, 20% or
ID: 3818222 • Letter: A
Question
At the President’s Day sale, a customer can bring in a coupon for a 10%, 20% or 30% discount off of total purchases. When paying, a clerk will use a VB application to record the sale. Based on the coupon presented, the clerk will select one of the following Radio Buttons named:
Discount10RadioButton,
Discount20RadioButton,
Discount30RadioButton.
This application also declares the following constants and variables:
Const DISCOUNT_10Decimal as Decimal = 0.1D
Const DISCOUNT_20Decimal as Decimal = 0.2D
Const DISCOUNT_30Decimal as Decimal = 0.3D
Write syntactically correct Visual Basic.NET code to calculate the final purchase price after discount and save it in the Decimal variable PurchaseTotalDecimal. The total purchase amount was already calculated and it is stored in the Decimal variable named PurchaseGrossTotalDecimal. No taxes are being charged.
Explanation / Answer
The problem can be broken in the following steps :
1. Identify the Radio Button selected and assign a discount value based on that.
2. Calculate the Gross Purchase . Formula to use PurchaseGrossTotalDecimal = (1 - Discount) * PurchaseTotalDecimal
The Code would go something like this.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Const DISCOUNT_10Decimal As Decimal = 0.1D
Const DISCOUNT_20Decimal As Decimal = 0.2D
Const DISCOUNT_30Decimal As Decimal = 0.3D
Dim Discount As Decimal = 0D
If RadioButton1.Checked = True Then
Discount = DISCOUNT_10Decimal
ElseIf RadioButton2.Checked = True Then
Discount = DISCOUNT_20Decimal
ElseIf RadioButton3.Checked Then
Discount = DISCOUNT_30Decimal
End If
//Calculate Gross Amount
Dim PurchaseGrossTotalDecimal As Decimal = (1 - Discount) * PurchaseTotalDecimal
MessageBox.Show(PurchaseGrossTotalDecimal)
End Sub
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.