100 likes | 111 Views
Create a modular program using Visual Basic to calculate payroll for a coffee shop, incorporating input validation, calculations, and proper display functions. Utilize various controls and methods for a user-friendly interface.
E N D
ASSIGNMENT OBJECTIVES LEARN TO USE: 1. Textboxes, labels, butttons, picture boxes, properties, radio buttons, checkbox, and methods, group boxes 2. Arithmetic computations 3. Variables and constants 4. IF THEN ELSE statements and CASE logic 5. Me.Close() 6. txtTextBox.Clear() and lblLabel.Text = “” 7. Procedures, Arguments and Parameters, ByVal and ByRef 8. FormatCurrency() and FormatNumber() functions 9. Use Google for help on FormatCurrency and FormatNumber. DIFFICULTY LEVEL: DIFFICULT TUTORING CENTER IS NOW OPEN START ON THE PROGRAM NOW. Know Chapters 1, 2, 3, 4 and 6 for this program. Spring 2015
GETTING HELP:You may ask another student for help, but you must not copy their code. Failure of the course will result for the person giving the code and the person receiving the code.REMEMBER: THE GRADES IN THIS COURSE ARE CURVED. I can get limited help from other students. For additional help, I need to see Dr. Scanlan, or the tutoring center.
Due Date: April 16, 2015 Points: 60 Late penalty: 50% per class day Programs are ONLY accepted at the START of the class period on the date due. General Requirement: Create a payroll calculator for a Coffee Shop Specific Requirements: Modularize Program 1. The GUI MUST look almost exactly like the one displayed below. 2. Use FormatCurrency() and FormatNumber() functions to display the amounts. Use dollar signs for Gross and Net pay and Totals only. 3. Use Me.Close to close the program 5. Use any picture of a coffee shop you can find by searching Google Images. 6. If Hours worked are over 40 then the employee receives time and one-half for the hours over 40. 7. Note: There are changes on the form from Program #2. 8. The Clear Button clears all amounts, Radio Buttons, and CheckBoxes. 9. Be sure to use dollar signs for Totals, Gross Pay and Net Pay.
10. You are to modularize the program according to the hierarchy chart below. The code for the Main Module and the Validate Data modules are given on the following slides. 11. Use lblLabel.Text = “” and txtTextBox.Clear() to clear labels and textboxes. 12. You may NOT use module-level variables. You must communicate between modules using arguments and parameters. 13. Use ByRef only when you are passing a value back to the calling module. 14. You must add a range test to the Validate Data module: Range: Hours Worked: 1 through 60 Range: Pay Rate: 10 through 15 15. You must use the code supplied on the next slides. Boss Module
Option Strict On 'You must use Option Strict On Public Class CalculateForm Inherits System.Windows.Forms.Form 'CONSTANT DECLARATIONS Const decFEDERAL_TAX_RATE As Decimal = 0.2D Const decSTATE_TAX_RATE As Decimal = 0.1D Const decCARBON_TAX_RATE As Decimal = 0.1D Const decMEDICAL_INSURANCE_RATE_PLAN_A As Decimal = 0.05D Const decMEDICAL_INSURANCE_RATE_PLAN_B As Decimal = 0.02D Const decMEDICAL_INSURANCE_RATE_PLAN_C As Decimal = 0.01D Const decDENTAL_INSURANCE_RATE_PLAN_A As Decimal = 0.05D Const decDENTAL_INSURANCE_RATE_PLAN_B As Decimal = 0.02D Const decDENTAL_INSURANCE_RATE_PLAN_C As Decimal = 0.01D Const decEYE_GLASSES As Decimal = 10D Const decEYE_EXAM As Decimal = 5D
'MAIN MODULE Private Sub btnCalcGrossPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcGrossPay.Click 'VARIABLE DECLARATIONS Dim decHoursWorked As Decimal Dim decPayRate As Decimal Dim decGrossPay As Decimal Dim decFederalTax As Decimal Dim decStateTax As Decimal Dim decCarbonTax As Decimal Dim decMedicalInsurance As Decimal Dim decDentalInsurance As Decimal Dim decVisionInsurance As Decimal Dim decNetPay As Decimal Dim decTotalTaxes As Decimal Dim decTotalHealthDeductions As Decimal Dim blnErrorFlag As Boolean = False Call ValidateData(blnErrorFlag, decHoursWorked, decPayRate) If blnErrorFlag = True Then Exit Sub End If Call CalculateGrossPay(decHoursWorked, decPayRate, decGrossPay) Call CalculateTaxes(decGrossPay, decFederalTax, decStateTax, decCarbonTax, decTotalTaxes) Call CalculateHealthInsurance(decGrossPay, decMedicalInsurance, decDentalInsurance, _ decVisionInsurance, decTotalHealthDeductions) Call CalculateNetPay(decGrossPay, decTotalTaxes, _ decTotalHealthDeductions, decNetPay) Call DisplayDeductions(decFederalTax, decStateTax, decCarbonTax, decTotalTaxes, _ decMedicalInsurance, decDentalInsurance, decVisionInsurance, _ decTotalHealthDeductions) Call DisplayGrossPayAndNetPay(decGrossPay, decNetPay) End Sub
'VALIDATE DATA Private Sub ValidateData(ByRef blnErrorFlag As Boolean, _ ByRef decHoursWorked As Decimal, _ ByRef decPayRate As Decimal) Try decHoursWorked = CDec(txtHoursWorked.Text) Catch ex As InvalidCastException MsgBox("Hours worked must be numeric.", MsgBoxStyle.Information, "Input Error") txtHoursWorked.BackColor = Color.Yellow txtHoursWorked.Focus() blnErrorFlag = True Exit Sub End Try Try decPayRate = CDec(txtPayRate.Text) Catch ex As Exception MsgBox("Pay rate must be numeric.", MsgBoxStyle.Information, "Input Error") txtPayRate.BackColor = Color.Yellow txtPayRate.Focus() blnErrorFlag = True Exit Sub End Try End Sub Don’t forget to add the range tests for Hours Worked and Pay Rate.
Warning: Attend to these grading criteria. Failure to organized program according to Hierarchy chart- 60 _____________ Failure to use ByVal and ByRef appropriately- 40 _____________ Inputted Pay Rate or Hourly Rate values outside of Validate Data module- 60_____________ Failure to use Option Strict On - 40 _____________
SPRING 2015 • Form-A GRADER FILLS IN THIS PAGE: PRINT LAST NAME:_______________________________ PRINT FIRST NAME:________________________ PROGRAM (Circle) 1 2 3 4 5 6 7 8 9 DATE DUE:_____________________DATE SUBMITTED:___________________ ATTENTION GRADER FILLS IN THESE BLANK DESCRIPTION POINTS POINTS EARNED Appropriate GUI: 0 OR 5 _____________ Used Variable names and constants correctly 0 OR 5 _____________ Failure to organized program according to Hierarchy chart- 20 _____________ Failure to use ByVal and ByRef appropriately (-20 for each failure -20 to -60 _____________ Inputted Pay Rate or Hourly Rate values outside of Validate Data module- 30 to -60_____________ Failure to use Option Strict On - 40 _____________ Program runs correctly: -20 to -60 _____________ Late penalty: -30 pts/class day _____________ Zero points if the program fails to compile _____________.TOTAL POINTS OUT OF A POSSIBLE 60: _____________ FAILURE TO HAND IN THE PROGRAM ACCORDING TO THE REQUIRED PROCEDURE: see next slide: -5 points Additional comments below:
Form-B CUT OUT THIS FORM ALONG THE DOTTED EDGES AND TAPE IT TO AN ENVELOPE ABOUT THE SIZE OF A CD or DVD-R . • STUDENT FILLS IN THESE BLANKS: • LAST NAME:_______________________________ • FIRST NAME:_______________________________ • PROGRAM (Circle) 1 2 3 4 5 6 7 8 • DATE DUE:_________________ • DATE SUBMITTED:__________________ • PLACE A CHECK NEXT TO THE FOLLOWING: • ____ Saved the Program on a CD-R or DVD-R using the following directory and sub-directory: Drive Letter:\Your Name\Program2 • ____ Printed your full name and program number on the CD or DVD-R using a • permanent black marker. • 3. ____ Submitted the CD or DVD-R in an envelope not to much larger than the CD. • ____ Placed the CD or DVD-R in the envelope.. • 5. ____ Cut out this form along dotted edges and securely tape it to the envelope. YOU MUST USE THIS STYLE THAT IS ABOUT THE SIZE OF YOUR CD. Do not lick to seal. Use metal clip. Be careful: Do not save your program on your DVD-R or CDusing the USB format..