Skip to content

Instantly share code, notes, and snippets.

@HopperMCS
Created March 24, 2019 21:36
Show Gist options
  • Save HopperMCS/00842c73888ff0863294b38028a68446 to your computer and use it in GitHub Desktop.
Save HopperMCS/00842c73888ff0863294b38028a68446 to your computer and use it in GitHub Desktop.
' Program Name: Pizza Project
' Program Description: Logs user in, then allows them to order a pizza with toppings. Calculates pizza price and delivery charges if applicable.
' This program also will show how many pizzas were ordered and deliveries that were made.
' Programmer: Matthew Gage Morgan
' Date: March 25th, 2019
Option Strict On
Public Class PizzaProject
' declare the two vars needed for running totals
Private GrandTotalPizzasOrdered As Integer
Private GrandTotalDeliveries As Integer
' constants for price of pizza sizes
Const PERSONAL_PAN As Decimal = 8D
Const NINE_INCH As Decimal = 10D
Const TWELVE_INCH As Decimal = 12D
Const FIFTEEN_INCH As Decimal = 14D
' constants for prices of pizza toppings
Const PEPPERONI As Decimal = 2D
Const SAUSAGE As Decimal = 2D
Const GREEN_PEPPER As Decimal = 1.5D
Const MUSHROOMS As Decimal = 1D
' constant for price of delivery charge (don't forget to also tip your driver too, because this doesn't go to them at most pizza places.)
Const DELIVERY_CHARGE As Decimal = 3D
Private Sub PizzaProject_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' I used the form's Load method to set the Calculate, Clear, and Show Totals buttons to be disabled on startup, as per the SPECS.
' The login form will re-enable these buttons when successfully logged in.
' I'm not actually sure if there's any other way to do this other than using the Load method.
CalculateCostButton.Enabled = False
ClearButton.Enabled = False
ShowTotalsButton.Enabled = False
End Sub
Private Sub LoginButton_Click(sender As Object, e As EventArgs) Handles LoginButton.Click
' declare the CustomerName and Password vars for the login form's logic
Dim CustomerName, Password As String
' set the CustomerName var to the value entered in the CustomerNameTextBox
CustomerName = CustomerNameTextBox.Text
' set the Password var to the value entered in the PasswordTextBox
Password = PasswordTextBox.Text
' if the CustomerNameTextBox contains visualbasic and the PasswordTextBox contains Winter, disable
' login form and enable the three buttons we disabled in the Load method
If CustomerName.ToLower = "visualbasic" AndAlso Password = "Winter" Then
CustomerNameTextBox.Enabled = False
PasswordTextBox.Enabled = False
LoginButton.Enabled = False
CalculateCostButton.Enabled = True
ClearButton.Enabled = True
ShowTotalsButton.Enabled = True
PersonalPanRadioButton.Checked = True
Else
' If login data is incorrect, show this MessageBox
MessageBox.Show("Sorry!! You are not validated!!", "LOGIN ERROR")
End If
End Sub
Private Sub CalculateCostButton_Click(sender As Object, e As EventArgs) Handles CalculateCostButton.Click
' declare the BasePrice, TotalToppings, DeliveryCost, and TotalPizzaCost vars for the CalculateButton logic
Dim BasePrice, TotalToppings, DeliveryCost, TotalPizzaCost As Decimal
' determine which size of pizza is checked by the user in the form. Set the BasePrice var declared above as the
' constant that matches the checked radio button.
If PersonalPanRadioButton.Checked = True Then
BasePrice = PERSONAL_PAN
ElseIf NineInchRadioButton.Checked = True Then
BasePrice = NINE_INCH
ElseIf TwelveInchRadioButton.Checked = True Then
BasePrice = TWELVE_INCH
ElseIf FifteenInchRadioButton.Checked = True Then
BasePrice = FIFTEEN_INCH
End If
' determine the toppings selected by the user. For each topping checked, add the corresponding topping's constant
' to the variable's current value
If PepperoniCheckBox.Checked = True Then
TotalToppings += PEPPERONI
End If
If SausageCheckBox.Checked = True Then
TotalToppings += SAUSAGE
End If
If GreenPepperCheckBox.Checked = True Then
TotalToppings += GREEN_PEPPER
End If
If MushroomCheckBox.Checked = True Then
TotalToppings += MUSHROOMS
End If
' If the user selected to have their pizza delivered, change the value of the DeliveryCost var to the value of the delivery charge constant, as well as
' add 1 to the running total of deliveries.
If DeliveryCheckBox.Checked = True Then
DeliveryCost = DELIVERY_CHARGE
GrandTotalDeliveries += 1
Else
' I don't know if this is actually needed, but it makes me feel safe, there are some languages that require this.
DeliveryCost = 0
End If
' Add this order to the variable storing the running total of pizzas ordered
GrandTotalPizzasOrdered += 1
' Calculate the total cost of pizza by addin the base price, toppings price, and delivery charge together.
' This is part of why I felt it appropriate to set "DeliveryCost" to 0 in the Else statement above.
TotalPizzaCost = BasePrice + TotalToppings + DeliveryCost
' Finally, display the cost of the total pizza as well as the cost of each topping selected, each display separately on two lines.
CustomerCostLabel.Text = "Total Pizza Cost Is: " & TotalPizzaCost.ToString("C2") & ControlChars.CrLf & "Total Topping Cost Is: " & TotalToppings.ToString("C2")
End Sub
Private Sub ClearButton_Click(sender As Object, e As EventArgs) Handles ClearButton.Click
' declare var for use to store the MessageBox answer
Dim answer As DialogResult
' Ask the user if they want to clear running totals in a MessageBox, record the answer in the "answer" var
answer = MessageBox.Show("Clear Totals Too???", "CLEAR TOTALS ???", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
' If the answer is Yes, clear the values of the running totals and clear the screen
' If the answer is No, just clear the screen and leave the values of the two running total vars alone
If answer = DialogResult.Yes Then
GrandTotalPizzasOrdered = 0
GrandTotalDeliveries = 0
PersonalPanRadioButton.Checked = True
PepperoniCheckBox.Checked = False
SausageCheckBox.Checked = False
GreenPepperCheckBox.Checked = False
MushroomCheckBox.Checked = False
DeliveryCheckBox.Checked = False
CustomerCostLabel.Text = String.Empty
Else
PersonalPanRadioButton.Checked = True
PepperoniCheckBox.Checked = False
SausageCheckBox.Checked = False
GreenPepperCheckBox.Checked = False
MushroomCheckBox.Checked = False
DeliveryCheckBox.Checked = False
CustomerCostLabel.Text = String.Empty
End If
End Sub
Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
' exit the application
Close()
End Sub
Private Sub ShowTotalsButton_Click(sender As Object, e As EventArgs) Handles ShowTotalsButton.Click
' when the Show Totals button is clicked, thise MessageBox pops up and shows the value of the
' running totals for both pizzas ordered And deliveries made.
MessageBox.Show("Total Number Of Pizzas: " & GrandTotalPizzasOrdered.ToString() & ControlChars.CrLf & "Total Number Of Deliveries: " & GrandTotalDeliveries.ToString(), "TOTALS")
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment