MCC - CIS162AD
CS4 Employee Pay Calculator - 20 points![]()
This program will be used by employees to determine what their weekly net pay would be based on their hourly rate and number of hours worked.
Sample Form:
![]()
Requirements:
Pseudocode for calculate button:
- Set the Text of the form to the assignment number and your name (CS4 Your Name).
- The borders around the various groups were created using the GroupBox object, and are usually drawn first before adding the labels and text boxes.
- The results of the calculations are displayed in Labels with AutoSize set to False and the BorderStyle set to Fixed3D.
- The labels on the left hand side do not have be given meaningful names, but the rest of control objects addressed in program code must have a meaningful name.
- Double click on the buttons to create the skeleton methods and to link the appropriate method to each click event. Don't just type in the method header as presented below. See page 173 on setting the event handler if the correct method is not executed when a button is clicked.
- The only class-level variables that should be used are cintEmployeeCount, cdecTotalNetpay, and the constants listed below. All other variables must be defined locally within their respective procedures.
Use constant variables to store the following values: cdecFICA_RATE = 0.06M cdecFEDERAL_RATE = 0.15M cdecSTATE_RATE = 0.05M cdecUNION_DUES = 10.00M- The user enters the number of hours worked and their hourly rate.
- The Calculate button is used to perform the calculations and display the results.
- Use a Try-Catch block to handle missing or bad input data instead of allowing the program to abort with a run-time error.
- Display a specific error message to the user if an error is detected.
- If the data is valid, the program should calculate gross pay, the three tax amounts, and net pay using the user input and constants provided.
- Also in this method count the number of employees processed, accumulate the net pay, and calculate the average net pay.
- Display the detail and summary values.
- The output should be formatted as currency with two digits after the decimal point. The count should NOT display the decimal point (N0).
You can choose your own variable names, but the formulas to use are: decGross = intHours * decRate; decFica = decGross * cdecFICA_RATE; decFederal = decGross * cdecFEDERAL_RATE; decState = decGross * cdecSTATE_RATE; decNetpay = decGross - (decFica + decFederal + decState + cdecUNION_DUES); cdecTotalNetpay += decNetpay; cintEmployeeCount += 1; decAverageNetpay = cdecTotalNetpay / cintEmployeeCount;Use these cases to test your program: Case # Worked Rate Netpay ------ ------ ---- -------- 1 25 9.25 161.13 2 45 15.00 489.50 Totals after both cases: Total Netpay: 650.63 Total Employee Count: 2 Average Netpay: 325.31- The Clear Form button is used to clear the two input text boxes, and all of the labels used to display the results of the calculations and summary totals.
In addition, the employee count and total netpay accumulator must be reset to zero (cintEmployeeCount = 0; and cdecTotalNetpay = 0;).
- The Exit button exits the program.
- Before beginning to write code:
- Make sure the requirements (problem) are understood.
- Sketch a form (see image above).
- List the name and property setting for each control object.
- Design the methods for each button using pseudocode.
- Build the project using the developed plan:
- Create the interface.
- Set the properties for the controls.
- Code the methods.
- Test the solution.
//CS4 by Your Name - CIS162AD namespace CS4 { public partial class frmCS4 : Form { public frmCS4() { InitializeComponent(); } //Declare class level variables (employee count and total netpay) //Declare class level constants (see list above) private void btnCalculate_Click(object sender, System.EventArgs e) { // declare method variables //Use nested try-catch blocks to get the input values //so we know which one caused the error try { //Get hours worked from textbox try { //Get pay rate from textbox //Calculate gross amount //Calculate taxes //Calculate net pay //Accumulate summary values //Calculate average net pay //Display results of calculations and summary values } catch (FormatException err) { MessageBox.Show("Pay Rate must be numeric. " + err.Message, "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtRate.SelectAll(); txtRate.Focus(); } } catch (FormatException err) { MessageBox.Show("Hours worked must be numeric. " + err.Message, "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtHours.SelectAll(); txtHours.Focus(); } catch (Exception err) { MessageBox.Show("Unexpected Error: " + err.Message); } }//end method private void btnClearForm_Click(object sender, EventArgs e) { //Use Clear or null string "" for TextBoxes, but //only use null string "" for Labels //Reset Accumulators } private void btnExit_Click(object sender, EventArgs e) { this.Close(); } }//end of class }//end of namespaceSubmit CS4Form.cs and CS4Form.Designer.cs
Revised: 09/23/2011 - www.mesacc.edu/~marquez/cis162ad/cs4_pay_calculator.html