Laboratory Exercise – Chapter 4

Payroll Application

Problem Description:

Develop an application that tracks the payroll for four departments: Management, Sales, Processing, and Phone. The user of the application will be able to enter a payroll amount and the department to which the payroll should be assigned. The application will determine if the department listed is valid as well as check to ensure that the payroll is a positive value. If inappropriate input is entered, a message box will be displayed indicating the error. Otherwise, the payroll will be added to the departments payroll total and output along with the other department totals in a label displayed on the form.

Your application should look as follows:

Problem Discussion:

The layout of your application is relatively simple. Your application will require a text box to allow the user to enter a department and payroll amount. Both text boxes should be labeled accordingly. You will need a button to process the payroll entered. You will also need a label to indicate the title of the application, as well as one to display the total payroll entered, so far, for each department.

You will require a variable to store each department’s payroll total. While the problem didn’t specify a range of values for a payroll, one can assume that it will be large. Therefore, you will use a Double to store each departments total.

The only other code required is to process the payroll entered. The code will require validating the data entered. The first check should be to see that the payroll amount is greater than 0. While it is not incorrect to add a payroll amount of 0, this will have no effect on the result and should be excluded. Once a valid payroll amount has been entered, the department must be validated. Your implementation should use a Select/Case statement for clarity and check for the capitalized. lowercase, and all uppercase versions of the department name. Therefore, for the management department your code should consider Management, management, and MANAGEMENT all valid departments.

Once the proper department has been determined, the payroll amount should be added to the appropriate variable.

Finally, the payroll totals should be output to the label.

Problem Solution:

Step 1: Create an Application called Thermostat.

Step 2: Rename the form in the Solution Explorer to frmPayroll.vb.

Step 3: Change the Name property of the form to frmPayroll.

Step 4: Change the Text property of the form to Payroll Application.

Step 5: Add a label control to the form.

Step 6: Change the Name property of the label to lblTitle.

Step 7: Change the Text property of the label to Payroll Application.

Step 8: Change the TextAlign property of the label to MidddleCenter.

Step 9: Change the Font Size to 16 and the Bold property to True.

 

Step 10: Add a label for the department text box.

Step 11: Change the Name property of the label to lblDepartment.

Step 12: Change the Text property of the label to Department.

Step 13: Change the Font Bold property to True.

 

Step 14: Add a text box for the department.

Step 15: Change the Name property of the label to txtDepartment.

Step 16: Clear the Text property.

Step 17: Add a label for the payroll amount text box.

Step 18: Change the Name property of the label to lblPayrollAmount.

Step 19: Change the Text property of the label to Payroll Amount.

Step 20: Change the Font Bold property to True.

 

Step 21: Add a text box for the payroll amount.

Step 22: Change the Name property of the label to txtPayrollAmount.

Step 23: Clear the Text property.

Step 24: Add a button to the form.

Step 25: Change the Name property of the button to btnAddPayroll.

Step 26: Change the Text property of the button to Add Payroll.

Step 27: Add a label to display the total payroll for each department.

Step 28: Change the Name property of the label to lblTotalPayroll.

Step 29: Clear the Text property of the label.

Step 30: Add the declaration of the variables to store the total payrolls of each department.

Step 31: Add the code to the button’s Click event. Follow the algorithm presented in the problem discussion.