Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Public Class frmInvoiceTotal Dim numberOfInvoices As Integer Dim totalOfInvoices As Decimal Dim invoiceAverage As Decimal Dim largestInvoice As Decimal = 0 Dim smallestInvoice As Decimal

Public Class frmInvoiceTotal

Dim numberOfInvoices As Integer Dim totalOfInvoices As Decimal Dim invoiceAverage As Decimal Dim largestInvoice As Decimal = 0 Dim smallestInvoice As Decimal = 999999999 Dim midPoint As Decimal = 0

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim customerType As String = txtCustomerType.Text Dim subtotal As Decimal = CDec(txtSubtotal.Text)

Dim discountPercent As Decimal Me.SetDiscountPercent(customerType, subtotal, discountPercent)

Dim discountAmount As Decimal = subtotal * discountPercent Dim invoiceTotal As Decimal = subtotal - discountAmount

txtDiscountPercent.Text = FormatPercent(discountPercent, 1) txtDiscountAmount.Text = FormatCurrency(discountAmount) txtTotal.Text = FormatCurrency(invoiceTotal)

numberOfInvoices = numberOfInvoices + 1 totalOfInvoices = totalOfInvoices + invoiceTotal invoiceAverage = totalOfInvoices / numberOfInvoices

txtNumberOfInvoices.Text = FormatNumber(numberOfInvoices, 0) txtTotalOfInvoices.Text = FormatCurrency(totalOfInvoices) txtInvoiceAverage.Text = FormatCurrency(invoiceAverage) largestInvoice = Math.Max(invoiceTotal, largestInvoice)

smallestInvoice = Math.Min(smallestInvoice, invoiceTotal)

midPoint = (largestInvoice + smallestInvoice) / 2

txtSmallestInvoice.Text = FormatCurrency(smallestInvoice) txtLargestInvoice.Text = FormatCurrency(largestInvoice) txtMidpoint.Text = FormatCurrency(midPoint)

txtCustomerType.Select() End Sub

Private Sub btnClearTotals_Click(sender As Object, e As EventArgs) Handles btnClearTotals.Click numberOfInvoices = 0 totalOfInvoices = 0 invoiceAverage = 0 largestInvoice = 0 smallestInvoice = 999999999 midPoint = 0

txtCustomerType.Text = "" txtSubtotal.Text = "" txtDiscountPercent.Text = "" txtDiscountAmount.Text = "" txtTotal.Text = "" txtNumberOfInvoices.Text = "" txtTotalOfInvoices.Text = "" txtInvoiceAverage.Text = "" txtLargestInvoice.Text = "" txtSmallestInvoice.Text = "" txtMidpoint.Text = ""

txtCustomerType.Select() End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub

Private Sub SetDiscountPercent(myCustomerType As String, mySubtotal As Decimal, ByRef myDiscountPercent As Decimal) 'If customer Type is "R" or "r" with a subtotal inferior to 100 get a discount Percent of 0% If myCustomerType = "R" OrElse myCustomerType = "r" Then If mySubtotal < 100 Then ' myDiscountPercent = 0

'if Customer type is "R" or "r" with a subtotal superior or equal to 100 and inferior to 250 get ' get a discount Percent of 20% ElseIf mysubtotal >= 100 AndAlso mysubtotal < 250 Then myDiscountPercent = 0.1D

' If customer Type is "R or "r" with a subtotal superior or equal to 250 and inferior to 500 get 'a discount Percent of 25% ElseIf mysubtotal >= 250 AndAlso mysubtotal < 500 Then myDiscountPercent = 0.25D

' if Customer type is "R or "r" with a subtotal superior or equal to 500 get discount Percent of 30% ElseIf mysubtotal >= 500 Then myDiscountPercent = 0.3D End If

' if customer type is "C" or "c" get a discount Percent of 20% ElseIf mycustomerType = "C" OrElse mycustomerType = "c" Then myDiscountPercent = 0.2D

' if customer type is "T" or "t" with a subtotal superior or equal to 500 get a discount Percent of 50% ElseIf mycustomerType = "T" OrElse mycustomerType = "t" Then If mySubtotal >= 500 Then myDiscountPercent = 0.5D

' if customer type is "T" or "t" with a subtotal which is not superior or equal to 500 'get a discount Percent of 40% Else myDiscountPercent = 0.4D End If

'If cutomer type is either "R" or "r" , either "C" or "c", either "T" or "t" get a discount Percent of 10% Else myDiscountPercent = 0.1D End If End Sub End Class

In visual basic, Considering this whole code, Make a Comment on the Sub Procedure "SetDiscountPercent". the comments should address the following issues:

1) what do the keywords Private and Sub mean?

2) What are the parameters of the procedure? What is the data type of each parameter? For mySubtotal and myDiscountPercent, how is the corresponding argument passed(by value or by reference)?

Also Comment on the calling statement.

1) what does the keyword Me mean?

2) Why the called Sub procedure can change the value of the argument discountPercent?

Please Take a closer look at the code. That is visual studio. Make sure you make the accurate comment. be accurate and good at visual Studio Please.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

what is a peer Group? Importance?

Answered: 1 week ago

Question

Write down the circumstances in which you led.

Answered: 1 week ago