Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.ComputeDiscountPercent(customerType, subtotal)

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) 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 Function ComputeDiscountPercent(myCustomerType As String, mySubtotal As Decimal) As Decimal Dim 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 Return myDiscountPercent End Function

Private Sub ClearAllBoxes(sender As Object, e As EventArgs) Handles_ txtCustomerType.DoubleClick, txtSubtotal.DoubleClick txtCustomerType.Text = "" txtSubtotal.Text = "" txtDiscountPercent.Text = "" txtDiscountAmount.Text = "" txtTotal.Text = ""

txtNumberOfInvoices.Text = "" txtTotalOfInvoices.Text = "" txtInvoiceAverage.Text = "" txtLargestInvoice.Text = "" txtSmallestInvoice.Text = ""

txtCustomerType.Text() End Sub End Class

5. Comment on the Function procedure ComputeDiscountPercent. Your comments should address the following issues: 4 1) What do the keywords Private and Function mean? 2) What does As Decimal at the end of the header of the procedure mean? 3) What are the parameters of the procedure? What is the data type of each parameter? For mySubtotal, how is the corresponding argument passed (by value or by reference)? 4) What does the Return statement do?

IN VISUAL STUDIO, ANALYZE THE CODE AND MAKE COMMENTS ON THE CODE. PUT THE ACCURATE CODE TO MAKE COMMENT ON AND MAKE THE ACCURATE COMMENT ON THE CODE PLEASE. PLEASE BE ACCURATE AND EFFICIENT IN VISUAL STUDIO. MAKE SURE TO SEE THE RIGHT PART OF THE CODE TO MAKE THE COMMENT ON AND MAKE THE ACCURATE COMMENT ON THE CODE. PLEASE.

the function procedure.

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Project management skills and/or experience desirable

Answered: 1 week ago