In: Computer Science
Visual Basics 2015 The local smoothie store, Smoothie Queen has hired you to develop a program that will make it easier for their sales associates to compute a customer's bill. You are to write a program that will allow the cashier to enter in customer information, smoothie information and display the total amount due. Here are the pertinent details: CALCULATIONS: 1. COST OF A SMOOTHIE: The actual cost of the smoothie is based on the smoothie size and the smoothie style. See the table below for price information. Internally you can handle this in one of two ways – you can either store this in a two-dimensional array/table or you can use an array of structures with two fields like you did in the state/abbreviation program. Small Medium Large King Regular 5.99 6.99 7.99 8.99 Organic 6.99 7.99 8.99 9.99 There are two different ways to approach the needed programming for the smoothie prices. You can use either of these – whichever one makes the most sense to you. My personal approach would be the first one (two dimensional arrays) because the data lays out like an Excel spreadsheet so it’s easy to think in rows and columns. But many people would also take the second approach (array of structures): A. Two-Dimensional Array Approach: If you are going to use a 2 dimensional array/table, you could declare it using something like this at the top of your program near your constants: decimal[,] smoothieListDecimal = {{ 5.99M, 6.99M, 7.99M, 8.99M }, { 6.99M, 7.99M, 8.99M, 9.99M }}; In this setup the cost for a particular smoothie would be based on a row and column of the table. For example, smoothieListDecimal [0, 3] would contain the price of a Regular King Smoothie. You will be able to use the selectedIndex for each of the dropdown lists to determine the row and column you need. TIP: You do not need a loop to search for the correct smoothie price. You only need to know the selectedIndex values for the row (smoothie style) and column (smoothie size) B. Array of Structures Approach: A different approach would be to use an array of structures. If you are going to use an array of structures, you could use a similar setup to the state/abbreviation program with the fields being regularDecimal and organicDecimal. You would then need an array of 4 structure elements (for each size) that you would initialize in the form load. 2. SMOOTHIE EXTRAS: A customer can order one or more extras for their smoothie. Toppings are $0.75 each (use a constant) and will be one of the following: Echinacea Bee Pollen Energy Booster 3. DISCOUNTS: A customer may receive a discount on their purchase. Discounts are computed before taxes and can be one of the following (use a constant): None – no discount Preferred customer card - 15% discount Coupon - 10% discount 4. TAXES: The final bill should also add in a state sales tax of 8% before calculating the amount due. You should incorporate a METHOD / FUNCTION to compute the tax. 5. CONSTANTS: Use appropriate constants for all numerical values that are predefined (e.g., extras, tax, discounts). FORMS SPECIFICATIONS AND VALIDATION 1. ABOUT FORM: Your program should have an “About” form that contains the typical information (program name, date, author, etc.). See sample EXE. 2. MAIN FORM (Customer Data): This form will need several components. There are also several required fields that should display appropriate error messages. When in doubt, refer to the sample EXE or post a question on the discussion board. 3. TEXT BOXES: You will use textboxes for the customer information. All fields must contain information or an error message will be displayed. • Customer Name TIP: You do not need to use a Try/Catch to do all the data validation since these are not numeric text fields. You can use a nested IF/ELSE setup to test the fields for the required input to make sure they are not blank. 4. COMBO BOXES/DROPDOWN LISTS • Smoothie Size: Should be one of the following – small, medium, large or king. Selection required. A size must be selected or an error should appear. Hint: Check to ensure the selectedIndex <> -1. • Smoothie Style: Should be one of the following – regular or organic. Selection required. A style must be selected or an error should appear. Hint: Check to ensure the selectedIndex <> -1. 5. CHECKBOXES/GROUPS: • Extras: Can be none, or, one or more of the following: Echinacea, Bee Pollen and Energy Booster. 6. RADIO BUTTONS/GROUPS: • Discount: May be none or 10% coupon or preferred customer (15% discount). 7. PULL DOWN MENUS (EXTRA CREDIT): The menu system should contain the following options (you can organize the menu choices however you’d like): • Calculate - Totals the customer's bill after adding any extras, deducting discounts and adding appropriate tax (assuming all data validation tests are passed). Displays the subtotal, discount, tax and amount due in the label box as currency. Note that if any validation error occurs, the program should not calculate or display any totals. • Clear - Clears all the text, check and option buttons, and totals. Repositions the cursor in the customer name text box for the next customer. • Help/About – Message box with your name and program name. • File/Exit - Exits the program. I have seen this posted before but wanted to see if someone would be able to explain more and possibly post screenshots of the code. Thank you in advance!
The Required code is given .
Images
CODE TO COPY
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim smoothieListDecimal(,) As Decimal = {{5.99D, 6.99D, 7.99D,
8.99D}, {6.99D, 7.99D, 8.99D, 9.99D}}
TextBox2.Text = Today()
TextBox1.Focus()
ComboBox1.Items.Add("Small")
ComboBox1.Items.Add("Medium")
ComboBox1.Items.Add("Large")
ComboBox1.Items.Add("King")
ComboBox2.Items.Add("Regular")
ComboBox2.Items.Add("Organic")
ComboBox3.Items.Add("Calculate")
ComboBox3.Items.Add("Clear")
ComboBox3.Items.Add("Help/About")
ComboBox3.Items.Add("File/Exit")
End Sub
Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox3.SelectedIndexChanged
Dim name, size, style As String
Dim extras As Double = 0, discount As Double = 0, subtot As Double,
amtdue As Double
Dim smoothieListDecimal(,) As Decimal = {{5.99D, 6.99D, 7.99D,
8.99D}, {6.99D, 7.99D, 8.99D, 9.99D}}
name = TextBox1.Text
If name = "" Then
TextBox1.Focus()
End If
size = ComboBox1.Text
If size = "" Then
ComboBox1.Focus()
End If
style = ComboBox2.Text
If style = "" Then
ComboBox2.Focus()
End If
If CheckBox2.Checked() = True Then
extras = extras + 0.75
End If
If CheckBox3.Checked() = True Then
extras = extras + 0.75
End If
If CheckBox4.Checked() = True Then
extras = extras + 0.75
End If
If RadioButton1.Checked() Then
discount = 0%
Else
If RadioButton2.Checked() Then
discount = 10%
Else
If RadioButton3.Checked() Then
discount = 15%
End If
End If
End If
If ComboBox3.Text = "Calculate" And name <> "" Then
Select Case size
Case "Small"
If style = "Regular" Then
subtot = smoothieListDecimal(0, 0)
Else
If style = "Organic" Then
subtot = smoothieListDecimal(1, 0)
End If
End If
Case "Medium"
If style = "Regular" Then
subtot = smoothieListDecimal(0, 1)
Else
If style = "Organic" Then
subtot = smoothieListDecimal(1, 1)
End If
End If
Case "Large"
If style = "Regular" Then
subtot = smoothieListDecimal(0, 2)
Else
If style = "Organic" Then
subtot = smoothieListDecimal(1, 2)
End If
End If
Case "King"
If style = "Regular" Then
subtot = smoothieListDecimal(0, 3)
Else
If style = "Organic" Then
subtot = smoothieListDecimal(1, 3)
End If
End If
End Select
subtot = subtot + extras
Label6.Text = Format(subtot, "$#,##0.00")
Label11.Text = discount & "%"
subtot = discount * subtot
Label12.Text = Format(subtot * 0.08, "$#,##0.00")
tax(subtot, amtdue)
Label13.Text = Format(amtdue, "$#,##0.00")
End If
If ComboBox3.Text = "Clear" Then
TextBox1.Focus()
TextBox1.Text = ""
End If
If ComboBox3.Text = "Help/About" Then
MsgBox("Smoothie Queen Author: ...................")
End If
If ComboBox3.Text = "File/Exit" Then
End
End If
End Sub
Function tax(ByVal subtot, ByRef amtdue) As Double
amtdue = subtot + subtot * 0.08
End Function
End Class
Output
Please Upvote.