MCC - Marquez - CIS162AD
CS5 Pay Calculator with Decisions - 20 points![]()
In this assignment, the previously completed project (CS4 Pay Calculator) will be enhanced to use If statements to valid the data entered, calculate overtime, and to determine the union dues based on the employee's membership. Radio Buttons will be used to allow the user to select their memberhship type. In addition, images will be added using Picture Boxes to enhance the appearance of the form :-).
Sample Form:
![]()
Requirements:
Pseudocode for calculate button:
- Consider making a copy of CS4 so it can be used as the starting the point.
The section where the amounts and totals are displayed and the buttons will need to be
moved down so that the Union Dues radio buttons can be added.
Create a new folder (CS5), and copy all files and folders from CS4 into the new folder (CS5).
Navigate to the new folder (CS5).
Do not rename the files in Windows Explorer.
Open the solution file and rename the files inside of Visual Studio.
- Group Boxes (p280, 286), Radio Buttons (p286), and Picture Boxes (734 3rd paragraph from the top).
Hints for Property values:
Radio Bottons: Create group first and then add buttons, to set None as the default set Checked = true for None
Picture Box: download pictures listed below, use Image to browsed to saved picture, SizeMode = StretchImage
- Include two picture boxes at the top of the form. You may used any appropriate picture or download these.
Internet Explorer may not display the images file (.ico) correctly, but you should still be able to
download the images as described in the next line.
Icon Files: Right-click on image and select Save Image As or Save Picture As.
Secured:Folder:
![]()
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 cdecNONE_UNION_DUES = 0.00M cdecREGULAR_UNION_DUES = 5.00M cdecSPECIAL_UNION_DUES = 10.00M- The user enters the number of hours worked and an 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 exception is thrown.
- After getting valid numeric data, use an if statement to check if the hours are between 1 and 50 inclusive. Display an error message if the value entered is outside the range.
- Use a nested if to check if the rate is between 10 and 15 dollars inclusive. Display an error message if the value enter is outside the range.
- If the hours and rate are within the range, process the data.
First calculate gross pay. Calculate overtime pay for the hours over 40 at 1.5 times the employee's payrate. In the actual code, add an M after 1.5 to make the data type decimal. The default data type for constants is double. The other option is to define a constant and use it in the calculation: const decimal cdecOVERTIME_RATE = 1.5M; You can choose your own variable names, but the formulas to use are: if (intHours <= 40) decGross = intHours * decRate; else decGross = (40 * decRate) + ((intHours - 40) * decRate * 1.5M);- Check which of the union membership radio buttons is selected to determine the amount to deduct. Use if-else statements to assign the correct amount stored in the constants to a local variable (decUnionDues).
Calculate the three tax amounts using the calculated gross pay and constants provided. decFica = decGross * cdecFICA_RATE; decFederal = decGross * cdecFEDERAL_RATE; decState = decGross * cdecSTATE_RATE;Then subtract the taxes and the union dues amount from gross pay to get the netpay. decNetpay = decGross - (decFica + decFederal + decState + decUnionDues);Count the number of employees processed, accumulate the net pay, calculate the average net pay, and then display the summary values. cdecTotalNetpay += decNetpay; cintEmployeeCount += 1; decAverageNetpay = cdecTotalNetpay / cintEmployeeCount;- The output should be formatted as currency with two digits after the decimal point. The count should NOT display the decimal point (N0).
- Use these cases to test your program:
Case # Worked Rate Union Type Netpay ------ ------ ---- ---------- ------ 1 30 10.00 None 222.00 2 40 12.00 Regular 350.20 3 50 15.00 Special 600.50 Totals after both cases: Total Netpay: 1172.70 Total Employee Count: 3 Average Netpay: 390.90- 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.
Reset the Union Membership radio button to None by setting its Checked property to true.
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.
//CS5 by Your Name - CIS162AD /* Enter program description here */ namespace CS5 { public partial class frmCS5 : Form ( public frmCS5() { InitializeComponent(); } //Declare class level variables (employee count and total netpay) //Declare class level constants (see list above) private void btnCalculate_Click(object sender, 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 //if statement to validate hours //if statement to validate pay rate { //We have valid Hours and PayRate - continue processing. //if statement to determine if overtime rate should be applied for gross //if statement to set Union Dues variable - check radio buttons //Calculate taxes //Calculate netpay by subtracting tax and union due amounts from gross //Accumulate summary totals //Calculate Average NetPay //Display the values in labels //Set focus on hours so user is ready to enter next employee } else { MessageBox.Show("Pay Rate must be between $10.00 and $15.00. ", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtRate.SelectAll(); txtRate.Focus(); } else { MessageBox.Show("Hours must be between 1 and 50. ", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtHours.SelectAll(); txtHours.Focus(); } } //Handle exception for Payrate catch (FormatException err) { MessageBox.Show("Pay Rate must be numeric. " + err.Message, "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtRate.SelectAll(); txtRate.Focus(); } } //Handle exception for Hours catch (FormatException err) { MessageBox.Show("Hours worked must be numeric. " + err.Message, "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtHours.SelectAll(); txtHours.Focus(); } //Handle all other exceptions catch (Exception err) { MessageBox.Show("Unexpected Error: " + err.Message); } }//end of btnCalculate private void btnClearForm_Click(object sender, EventArgs e) { //Use Clear or null string "" for TextBoxes, but //only use null string "" for Labels //Set radNone.Checked = true; //Reset Accumulators }//end of btnClearForm private void btnExit_Click(object sender, EventArgs e) { this.Close(); } }//end of class }//end of namespaceSubmit CS5Form.cs and CS5Form.Designer.cs
Revised: 09/27/2011 - www.mesacc.edu/~marquez/cis162ad/cs5_decisions.html