Home

Example Application: Danilo Pizza

 

This application is used to explore the fundamental characteristics of radio buttons and check boxes. A clerk uses radio buttons to select the size of a pizza (small, medium, or large). Some check boxes are used to select the toppings. A function is used to calculate the cost of the pizza. This is done live as the user makes the normal selections or enters the quantities of such items as the bottles of soda, bread sticks, or Buffalo wings.  

     

Practical Learning Practical Learning: Introducing Check Boxes

  1. Start a new Windows Application named DaniloPizza1
  2. In the Solution Explorer, right-click Form1.cs and click Rename
  3. Type Exercise.vb and press Enter
  4. On the main menu, click Project -> Add New Item...
  5. In the Templates list, click Icon File
  6. Set the Name to pizza and click Add
  7. Using the Erase tool Erase, wipe its interior to erase its content
  8. Use the Ellipse tool and the black color to draw an oval shape
     
    Pizza
  9. Fill Fill it up with a brown color (the color on the right side of the black)
  10. Click the red color
  11. Click the Airbrush tool Air Brush
  12. Click the option button and select the Medium brush
     
    Medium Air Brush
  13. Randomly click different parts of the shape
     
  14. To give the appearance of a crust, use the Pencil tool Pencil, click the black color, right-click the brown color, and draw a dark border around the shape
  15. With still the black and the brown colors, randomly click and right-click different points in the shape:
     
    Pizza
  16. Click the white color. Right-click the yellow color. Randomly click and right-click a few times in the shape
  17. Click the brown color again and click the Line tool Line
  18. Randomly draw horizontal, vertical, and dialog lines in the shape
     
    Pizza
  19. Right-click a white section in the drawing area, position the mouse on Current Icon Image Types, and click 16x16, 16 Colors
  20. Design it as follows:
     
    Pizza
  21. Save the icon and close it
  22. Use the Icon field of the form in the Properties window to assign the pizza.ico icon to the form
  23. Design the form as follows:
     
    Danilo Pizza - Design
     
    Control Text Name Additional Properties
    GroupBox GroupBox Pizza Size    
    RadioButton RadioButton Small rdoSmall  
    TextBox TextBox 8.95 txtSmall AlignText: Right
    RadioButton RadioButton Medium rdoMedium Checked: True
    TextBox TextBox 10.75 txtMedium AlignText: Right
    RadioButton RadioButton Large rdoLarge  
    TextBox TextBox 12.95 txtLarge AlignText: Right
    GroupBox GroupBox Side Orders    
    Label Label Qty    
    Label Label Unit Price    
    Label Label Sub Total    
    Label Label Bread Sticks    
    TextBox TextBox 0 txtQtyBread AlignText: Right
    TextBox TextBox 3.25 txtPriceBread AlignText: Right
    TextBox TextBox 0.00 txtTotalBread AlignText: Right
    ReadOnly: True
    Label Label Buffalo Wings    
    TextBox TextBox 0 txtQtyWings AlignText: Right
    TextBox TextBox 2.15 txtPriceWings AlignText: Right
    TextBox TextBox 0.00 txtTotalWings AlignText: Right
    ReadOnly: True
    GroupBox GroupBox Toppings    
    CheckBox CheckBox Pepperoni chkPepperoni  
    CheckBox CheckBox Sausage chkSausage  
    CheckBox CheckBox Extra Cheese chkExtraCheese  
    CheckBox CheckBox Olives chkOlives  
    CheckBox CheckBox Onions chkOnions  
    Label Label Each Topping    
    TextBox TextBox 0.45 txtEachTopping AlignText: Right
    GroupBox GroupBox Drinks    
    Label Label Qty    
    Label Label Unit Price    
    Label Label Sub Total    
    Label Label Soda Can    
    TextBox TextBox 0 txtQtyCan AlignText: Right
    TextBox TextBox 1.45 txtPriceCan AlignText: Right
    TextBox TextBox 0.00 txtTotalCan AlignText: Right
    ReadOnly: True
    Label Label Soda 20 Oz.    
    TextBox TextBox 0 txtQtySoda20 AlignText: Right
    TextBox TextBox 1.45 txtPriceSoda20 AlignText: Right
    TextBox TextBox 0.00 txtTotalSoda20 AlignText: Right
    ReadOnly: True
    Label Label Soda 2L Bottle    
    TextBox TextBox 0 txtQtySoda2L AlignText: Right
    TextBox TextBox 1.45 txtPriceSoda2L AlignText: Right
    TextBox TextBox 0.00 txtTotalSoda2L AlignText: Right
    ReadOnly: True
    Label Label Orange Juice    
    TextBox TextBox 0 txtQtyOJ AlignText: Right
    TextBox TextBox 2.25 txtPriceOJ AlignText: Right
    TextBox TextBox 0.00 txtTotalOJ AlignText: Right
    ReadOnly: True
    Label Label Water    
    TextBox TextBox 0 txtQtyWater AlignText: Right
    TextBox TextBox 1.25 txtPriceWater AlignText: Right
    TextBox TextBox 0.00 txtTotalWater AlignText: Right
    ReadOnly: True
    Button Button Close btnClose  
    Label Label Total Price    
    TextBox TextBox 0.00 txtTotalPrice AlignRight: Right
    ReadOnly: True
  24. Save everything
  25. Right-click the form and click View Code
  26. Inside the class, create the following procedure:
     
    Public Class Exercise
    
        Private Sub CalculatePrice()
            Dim PriceSize As Double
            Dim PriceEachTopping As Double
            Dim BWings As Double
            Dim Bread As Double
            Dim SodaCan As Double
            Dim Soda20 As Double
            Dim Soda2L, OJ As Double
            Dim Water As Double
            Dim PriceToppings As Double
            Dim TotalOrder As Double
            Dim Pepperoni As Integer
            Dim Sausage As Integer
            Dim ExtraCheese As Integer
            Dim Onions As Integer
            Dim Olives As Integer
    
            Try
                ' Get the price of pizza depending on the selected size
                If rdoSmall.Checked = True Then
                    PriceSize = CDbl(txtSmall.Text)
                End If
    
                If rdoMedium.Checked = True Then
                    PriceSize = CDbl(txtMedium.Text)
                End If
    
                If rdoLarge.Checked = True Then
                    PriceSize = CDbl(txtLarge.Text)
                End If
            Catch ex As Exception
                MsgBox("The value you typed for the " & 
    		     "price of a pizza is invalid" & 
                                vbCrLf & "Please try again")
            End Try
    
            ' Get the price of a topping if it was selected
            If chkPepperoni.Checked = True Then
                Pepperoni = 1
            Else
                Pepperoni = 0
            End If
    
            If chkSausage.Checked = True Then
                Sausage = 1
            Else
                Sausage = 0
            End If
    
            If chkExtraCheese.Checked = True Then
                ExtraCheese = 1
            Else
                ExtraCheese = 0
            End If
    
            If chkOnions.Checked = True Then
                Onions = 1
            Else
                Onions = 0
            End If
    
            If chkOlives.Checked = True Then
                Olives = 1
            Else
                Olives = 0
            End If
    
            ' Get the price of each topping
            Try
                PriceEachTopping = CDbl(txtEachTopping.Text)
            Catch
                MsgBox("The value you typed for the price " & 
    		     "of a each topping is invalid" & 
                        vbCrLf & "Please try again")
            End Try
    
            PriceToppings = (Pepperoni + Sausage + ExtraCheese + 
                            Onions + Olives) * PriceEachTopping
    
            ' Calculate the price of the side dishes
            ' depending on the quantity entered
            BWings = CDbl(txtTotalWings.Text)
            Bread = CDbl(txtTotalBread.Text)
    
            ' Calculate the price of the drink(s)
            SodaCan = CDbl(txtTotalCan.Text)
            Soda20 = CDbl(txtTotalSoda20.Text)
            Soda2L = CDbl(txtTotalSoda2L.Text)
            OJ = CDbl(txtTotalOJ.Text)
            Water = CDbl(txtTotalWater.Text)
    
            TotalOrder = PriceSize + PriceToppings + BWings + Bread + 
                SodaCan + Soda20 + Soda2L + OJ + Water
            txtTotalOrder.Text = FormatNumber(TotalOrder)
    
        End Sub
    End Class
  27. Under the above procedure, create the following procedure:
     
    Private Sub rdoSmallClick(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles rdoSmall.Click, 
                                           rdoMedium.Click, 
                                           rdoMedium.Click, 
                                           chkExtraCheese.Click, 
                                           chkOlives.Click, 
                                           chkOnions.Click, 
                                           chkPepperoni.Click, 
                                           chkSausage.Click
    
            CalculatePrice()
    End Sub
  28. Under the above procedure, create the following procedure:
     
    Private Sub ItemPriceLeave(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles txtSmall.Leave, 
                                   txtMedium.Leave, 
                                   txtLarge.Leave, 
                                   txtMedium.Leave, 
                                   txtLarge.Leave, 
                                   txtEachTopping.Leave, 
                                   txtQtyBread.Leave, 
                                   txtPriceBread.Leave, 
                                   txtQtyWings.Leave, 
                                   txtPriceWings.Leave, 
                                   txtQtyCan.Leave, 
                                   txtPriceCan.Leave, 
                                   txtQtySoda20.Leave, 
                                   txtPriceSoda20.Leave, 
                                   txtQtySoda2L.Leave, 
                                   txtPriceSoda2L.Leave, 
                                   txtQtyOJ.Leave, 
                                   txtPriceOJ.Leave, 
                                   txtQtyWater.Leave, 
                                   txtPriceWater.Leave
            Dim QtyBread As Integer
            Dim QtyWings As Integer
            Dim QtyCan As Integer
            Dim QtySoda20 As Integer
            Dim QtySoda2L As Integer
            Dim QtyOJ As Integer
            Dim QtyWater As Integer
    
            Dim PriceBread As Double
            Dim TotalBread As Double
            Dim PriceWings As Double
            Dim TotalWings As Double
            Dim PriceCan As Double
            Dim TotalCan As Double
            Dim PriceSoda20 As Double
            Dim TotalSoda20 As Double
            Dim PriceSoda2L As Double
            Dim TotalSoda2L As Double
            Dim PriceOJ As Double
            Dim TotalOJ As Double
            Dim PriceWater As Double
            Dim TotalWater As Double
    
            ' Retrieve the quantity set in the text box
            Try
                QtyBread = CInt(txtQtyBread.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the quantify " & 
                       "of bread sticks is not valid" & 
                       vbCrLf & "Please try again!")
            End Try
    
            ' Get the unit price of the item
            Try
                PriceBread = CDbl(txtPriceBread.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the price " & 
                       "of bread sticks is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            ' Calculate the sub-total of this item
            TotalBread = QtyBread * PriceBread
            ' Display the sub-total in the corresponding text box
            txtTotalBread.Text = TotalBread.ToString("F")
    
            Try
                PriceWings = CInt(txtQtyWings.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the quantify " & 
                       "of orders of buffalo wings is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            Try
                PriceWings = CDbl(txtPriceWings.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the price " & 
                       "of buffalo wings is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            TotalWings = QtyWings * PriceWings
            txtTotalWings.Text = TotalWings.ToString("F")
    
            Try
                QtyCan = CInt(txtQtyCan.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the " & 
                       "quantify of soda cans is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            Try
                PriceCan = CDbl(txtPriceCan.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the " & 
                       "price of soda cans is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            TotalCan = QtyCan * PriceCan
            txtTotalCan.Text = TotalCan.ToString("F")
    
            Try
                QtySoda20 = CInt(txtQtySoda20.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the " & 
                       "quantify of soda 20 Oz. is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            Try
                PriceSoda20 = CDbl(txtPriceSoda20.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the " & 
                       "price of soda 20 Oz. is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            TotalSoda20 = QtySoda20 * PriceSoda20
            txtTotalSoda20.Text = TotalSoda20.ToString("F")
    
            Try
                QtySoda2L = CInt(txtQtySoda2L.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the quantify " & 
                       "of bottles of soda 2-litter is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            Try
                PriceSoda2L = CDbl(txtPriceSoda2L.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the price " & 
                       "of a bottle of soda is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            TotalSoda2L = QtySoda2L * PriceSoda2L
            txtTotalSoda2L.Text = TotalSoda2L.ToString("F")
    
            Try
                QtyOJ = CInt(txtQtyOJ.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the quantify " & 
                       "of a bottle of orange juice is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            Try
                PriceOJ = CDbl(txtPriceOJ.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the price " & 
                       "of bottles of orange is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            TotalOJ = QtyOJ * PriceOJ
            txtTotalOJ.Text = TotalOJ.ToString("F")
    
            Try
                QtyWater = CInt(txtQtyWater.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the quantify " & 
                       "of bottles of water is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            Try
                PriceWater = CDbl(txtPriceWater.Text)
            Catch ex As Exception
                MsgBox("The value you entered for the price " & 
                       "of bottle of water is not valid" & 
                    vbCrLf & "Please try again!")
            End Try
    
            TotalWater = QtyWater * PriceWater
            txtTotalWater.Text = TotalWater.ToString("F")
    
            CalculatePrice()
    End Sub
  29. In the Class Name combo box, select btnClose
  30. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnCloseClick(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles btnClose.Click
            End
    End Sub
  31. Execute the application and test the form. Here is an example:
     
    Danilo Pizza - Results
  32. Close the form and return to your programming environment

Download

 

Home Copyright © 2008-2016, FunctionX, Inc.