Bakery project
Program plan:
- Create new Windows Forms Application.
- Design the form by placing the labels, textboxes, and buttons and then change their name and properties.
- Inside the “Calculate” button,
- Declare the required variables.
- Assign the name to the variable.
- Get the item price.
- Convert the string type values into a decimal value.
- Get the muffin price.
- Convert the string type values into a decimal value.
- Convert the string type values into the integer values
- Calculate the total item, subtotal of the item, sales tax, and total sales.
- Display the total amount, tax, and salesclerk’s name.
- Inside the “Clear Screen” button,
- Clear all the dates except date.
- Inside the “Exit” button,
- Close the form using “Me.Close” method
- Inside the “Print Receipt” button,
- Print the sales receipt.
- Inside the “ClearLabels”,
- Clear the calculated amounts.
This program is used to allow the user to enter the doughnut price, muffin price and then calculate the total items and total costs.
Explanation of Solution
Program:
'Definition of class frmMain
Public Class frmMain
'Definition of calculate
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
' Declare the variables
Const strPROMPT As String = "Salesclerk's name:"
Const strTITLE As String = "Name Entry"
Const decTAX_RATE As Decimal = 0.02D
Dim intDonuts As Integer
Dim intMuffins As Integer
Dim intTotalItems As Integer
Dim decSubtotal As Decimal
Dim decSalesTax As Decimal
Dim decTotalSales As Decimal
Static strClerk As String
Static strDonutPrice As String
Static strMuffinPrice As String
Dim decDonutPrice As Decimal
Dim decMuffinPrice As Decimal
'Assign name to variable
strClerk = InputBox(strPROMPT, strTITLE, strClerk)
'Get item prices
strDonutPrice = InputBox("Doughnut price:", "Doughnut Price Entry", strDonutPrice)
'Convert the string type value into a decimal 'value
Decimal.TryParse(strDonutPrice, decDonutPrice)
'Get muffin price
strMuffinPrice = InputBox("Muffin price:", "Muffin Price Entry", strMuffinPrice)
'Convert the string type value into a decimal 'value
Decimal.TryParse(strMuffinPrice, decMuffinPrice)
'Convert the string type’s value into an 'integer values
Integer.TryParse(txtDonuts.Text, intDonuts)
Integer.TryParse(txtMuffins.Text, intMuffins)
'Calculate the total items
intTotalItems = intDonuts + intMuffins
'Calculate the subtotal
decSubtotal = intDonuts * decDonutPrice + intMuffins * decMuffinPrice
'Calculate the sales tax
decSalesTax = decSubtotal * decTAX_RATE
'Calculate the total sales
decTotalSales = decSubtotal + decSalesTax
'Display total amounts
lblTotalItems.Text = Convert.ToString(intTotalItems)
lblTotalSales.Text = decTotalSales.ToString("C2")
'Display tax and salesclerk's name
lblMsg.Text = "The sales tax was " &
decSalesTax.ToString("C2") & "." &
ControlChars.NewLine & strClerk
End Sub
'Definition of Clear button
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'Clear calculated amounts
txtDonuts.Text = String.Empty
txtMuffins.Text = String.Empty
lblTotalItems.Text = String.Empty
lblTotalSales.Text = String.Empty
lblMsg.Text = String.Empty
'Send the focus to the Doughnuts box
txtDonuts.Focus()
End Sub
'Definition of button Exit
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'Close the form
Me.Close()
End Sub
'Definition of button Print
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
'Print the sales receipt
btnCalc.Visible = False
btnClear.Visible = False
btnExit.Visible = False
btnPrint.Visible = False
PrintForm1.Print()
btnCalc.Visible = True
btnClear.Visible = True
btnExit.Visible = True
btnPrint.Visible = True
End Sub
'Definition of "ClearLabels"
Private Sub ClearLabels(sender As Object, e As EventArgs) _
Handles txtDonuts.TextChanged, txtMuffins.TextChanged
'Clear the total items, total sales, and 'message
lblTotalItems.Text = String.Empty
lblTotalSales.Text = String.Empty
lblMsg.Text = String.Empty
End Sub
End Class
Output:
Enter the date, doughnuts, and muffins. Then click “Calculate” button.
Screenshot of “Meyer’s Purple Bakery” form
Enter the salesclerk name and then “OK” button.
Screenshot of “Name Entry” form
Enter the Doughnut price and then “OK” button.
Screenshot of “Doughnut Price Entry” form
Enter the muffin price and then “OK” button.
Screenshot of “Muffin Price Entry” form
Screenshot of “Meyer’s Purple Bakery” form
After clicking “Print Receipt” button the following window will appear:
Screenshot of “Print preview” form
After clicking “Clear Screen” button the entire textbox is cleared except date:
Screenshot of “Meyer’s Purple Bakery” form
Want to see more full solutions like this?
Chapter 3 Solutions
Programming with Microsoft Visual Basic 2015 (MindTap Course List)
- In this exercise, you modify the Grade Calculator application from this chapter’s Apply lesson. Use Windows to make a copy of the Grade Solution folder. Rename the copy Grade Solution-Intermediate. Open the Grade Solution.sln file contained in the Grade Solution-Intermediate folder. Open the CourseGrade.vb file. The DetermineGrade method should accept an integer that represents the total number of points that can be earned in the course. (Currently, the total number of points is 200: 100 points per test.) For an A grade, the student must earn at least 90% of the total points. For a B, C, and D grade, the student must earn at least 80%, 70%, and 60%, respectively. If the student earns less than 60% of the total points, the grade is F. Make the appropriate modifications to the DetermineGrade method and then save the solution. Unlock the controls on the form. Add a label control and a text box to the form. Change the label control’s Text property to “&Maximum points:” (without the quotation marks). Change the text box’s name to txtMax. Lock the controls and then reset the tab order. Open the form’s Code Editor window. The txtMax control should accept only numbers and the Backspace key. Code the appropriate procedure. The grade should be cleared when the user makes a change to the contents of the txtMax control. Code the appropriate procedure. Modify the frmMain_Load procedure so that each list box displays numbers from 0 through 200. Locate the btnDisplay_Click procedure. If the txtMax control does not contain a value, display an appropriate message. The maximum number allowed in the txtMax control should be 400; if the control contains a number that is more than 400, display an appropriate message. The statement that calculates the grade should pass the maximum number of points to the studentGrade object’s DetermineGrade method. Make the necessary modifications to the procedure. Save the solution and then start and test the application.arrow_forwardWindow 1Should have a welcome message, a textbox to receive AN EXISTING ID of the user and a button to access the data base. All users ID should be saved in a data base (Don’t use access). Once the Id is verified then the program will give the user access to the main menu window.Your database should have the following columns. Use SQL/mySQL to create the database and Netbeans as the IDE.arrow_forwardIn this exercise, you will create the Jacobson Furniture application. The application’s Planning Chart is shownbelow.a. Use either a flowchart or pseudocode to plan the btnCalc_Click procedure, which should calculate anddisplay both a 5% sales tax and the total due.b. Create a Windows Forms application. Use the following names for the project and solution,respectively: FamilyName_Furniture Project and FamiltyName_Furniture Solution. Save the applicationin the VB2019\Exercise2 folder. Enter the three Option statements in the Code Editor window. Codethe btnCalc_Click procedure using variables and a named constant. Display the sales tax with a comma(if necessary) and two decimal places. Display the total due with a comma (if necessary), a peso signand two decimal places. Save the solution and then start and test the application. (If the sales amountis 500, the sales tax and total due are 25.00 and P525.00, respectively.)c. Now professionalize your interface by coding the text box’s…arrow_forward
- The user must have the ability to search for a product. The user will select menu itemtwo (2), which will prompt the user to enter a product code. If a valid product is found inthe application, then display the product details to the user. If no valid product is found,display an error message to the user that the product cannot be located.arrow_forwardOpen the Proper Case Solution.sln file contained in the VB2017\Chap07\ProperCase Solution folder. The interface provides a text box for entering a person’s first andlast names. The btnProper_Click procedure should display the first and last namesin the proper case. In other words, the first and last names should begin with anuppercase letter and the remaining letters in each name should be lowercase. If the userenters only one name, display the name in proper case. Be sure the btnProper_Clickprocedure works correctly if the user inadvertently enters more than one space betweenthe first and last names. After displaying the name, the procedure should send the focusto the txtName control. Code the procedure. Save the solution and then start and testthe application. (If the user enters “john smith” as the name, the application shoulddisplay “John Smith”. If the user enters “carol” followed by three spaces and then “jones”,the application should display “Carol Jones”. If the user enters…arrow_forwardThe application must allow the user to enter the student ID. When the search button is clicked, it should open a text file with the list of students, then search for the student ID in the text file. Once the ID has been found, it should show the full student details in a textbox as shown below: Siyabonga School App Welcome to Siyabonga School Enter Student ID 0006043432 Manaane Van Der Wait 0006043432 Grade 6 Search X1ipg Eing Aingarrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning