Skip to content

Commit

Permalink
Add functions to expand codes via a dictionary
Browse files Browse the repository at this point in the history
* Can easily be changed to use ints to represent types/toppings
  • Loading branch information
aiden2480 committed Nov 5, 2021
1 parent 9debfbc commit 6710256
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions VB-Pizza-v102/Pizza102.vb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,40 @@ Public Class Pizza102
txtTotalcost.Text = FormatCurrency(cost + 3) ' Add on delivery fees
End Sub

' Convert crust and toppings codes to their proper form
Private Function ExpandPizzaCode(code As Char)
Return New Dictionary(Of Char, String) From {
{"r", "Regular"},
{"t", "Thick"},
{"c", "Cheesy"}
}(code)
End Function

Private Function ExpandToppings(toppings As List(Of String)) As String
Dim concat As String = ""
Dim conv As New Dictionary(Of String, String) From {
{"mus", "mushroom"},
{"pin", "pineapple"},
{"pep", "pepperoni"},
{"ham", "ham"},
{"anc", "anchovies"},
{"oli", "olives"}
}

For Each topping In toppings
concat += conv(topping) + ", "
Next

' Deal with an edge case where the string might be empty because
' no toppings were selected, in which case splicing the string
' would break the program, so we check that the string isn't empty
If concat <> "" Then
concat = concat.Substring(0, concat.Length() - 2)
End If

Return If(concat <> "", concat, "No toppings")
End Function

' Event listeners
Private Sub CrustRadioboxChanged() Handles chkRegularcrust.CheckedChanged, chkThickcrust.CheckedChanged, chkCheesecrust.CheckedChanged
CalculateCrustCost()
Expand Down

0 comments on commit 6710256

Please sign in to comment.