Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

LAB #4: In lab 4, we will use two new controls; ComboBox and ListBox, as well as

ID: 3605239 • Letter: L

Question

LAB #4:

In lab 4, we will use two new controls; ComboBox and ListBox, as well as separate About form.

Create a project for local coffee shop.

Your design should consist of three frame controls:

The first frame control that has Command Buttons of: Add Coffee Flavor, Remove Coffee Flavor, Clear Coffee List, and Count Coffee List. As an alternative you may have menu for these options (better alternative).

The second frame control that has a ComboBox, for selecting coffee flavors such as (Espresso, Latte, Cappuccino, Mocha, Americana), and a ListBox that has the list of Syrup flavors such as (Almond, Amaretto, Caramel, Chocolate Milano, Cinnamon).

The third frame control has Exit, Clear and About commands.

NOTE: You can move the contents of first and third frame controls to a MenuStrip for better readability.

Activities:

In case of Add Coffee Flavor, the desired coffee flavor must be typed in a textbox. Program checks the list and notifies the user if that flavor is already in the list. Also, do not allow a blank coffee name to be added to the list.

In case of Count Coffee List, the message box lists the number of coffee flavors in the list.

Before clearing the list, display a message box to confirm the operation. Also, the user must be notified that the list is cleared.

Display error message if the user selects Remove without first selecting the name.

The program should also create and initialize two arrays, one to keep prices for coffee flavors, and one for syrup flavors (Provide your own data). You may make the syrup price as a constant value (ex $2.50). When the user selects a coffee flavor and/or syrup flavor display information about item(s) selected and their prices.

There will be separate About form named Help that has the name of programmer along with subject of the program.

Explanation / Answer

Public Class Form1
Dim coffeeList As New List(Of String)
Dim syrupList As New List(Of String)
Dim syrupPrice As Double
Dim coffeePrice As New List(Of Double)
Private Sub AddCoffeeFlavourToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddCoffeeFlavourToolStripMenuItem.Click
If txtCoffeeFlavour.Text = "" Or txtPrice.Text = "" Then
MessageBox.Show("Please provide both coffee flavour and it's price.", "Error", MessageBoxButtons.OK)
Else
If coffeeList.Contains(txtCoffeeFlavour.Text) Then
MessageBox.Show("Flavour already present in the list.", "Error", MessageBoxButtons.OK)
Else
comboCoffee.Items.Add(txtCoffeeFlavour.Text)
coffeeList.Add(txtCoffeeFlavour.Text)
coffeePrice.Add(Val(txtPrice.Text))
txtCoffeeFlavour.Text = ""
txtPrice.Text = ""
End If
End If
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
syrupPrice = 2.5
listSyrup.Items.Add("Almond")
listSyrup.Items.Add("Amaretto")
listSyrup.Items.Add("Caramel")
listSyrup.Items.Add("Chocolate")
listSyrup.Items.Add("Milano")
listSyrup.Items.Add("Cinnamon")
labelSyrupPrice.Text = syrupPrice
End Sub

Private Sub CountCoffeeListToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CountCoffeeListToolStripMenuItem.Click
MessageBox.Show("Number of coffee flavours: " & coffeeList.Count, "Total coffee flavours", MessageBoxButtons.OK)
End Sub

Private Sub ClearCoffeeListToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClearCoffeeListToolStripMenuItem.Click
If MessageBox.Show("Are you sure about clearing the list?", "Clear list", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
comboCoffee.Items.Clear()
coffeeList.Clear()
coffeePrice.Clear()
MessageBox.Show("List has been cleared.", "List cleared", MessageBoxButtons.OK)
End If
End Sub

Private Sub comboCoffee_SelectedIndexChanged(sender As Object, e As EventArgs) Handles comboCoffee.SelectedIndexChanged
labelCoffeePrice.Text = coffeePrice(coffeeList.IndexOf(comboCoffee.SelectedText) + 1)
End Sub

Private Sub RemoveCoffeeFlavourToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles RemoveCoffeeFlavourToolStripMenuItem1.Click
If String.IsNullOrEmpty(comboCoffee.SelectedText) Then
MessageBox.Show("Please select a coffee flavour to remove.", "Error", MessageBoxButtons.OK)
Else
coffeePrice.RemoveAt(coffeeList.IndexOf(comboCoffee.SelectedText))
coffeeList.Remove(comboCoffee.SelectedText)
comboCoffee.Items.Remove(comboCoffee.SelectedText)
End If
End Sub
End Class