|
CS5 Pay Calculator with Decisions - 25 points |
|
In this program 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:
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:
cdecNONE_UNION_DUES = 0.00M cdecREGULAR_UNION_DUES = 5.00M
cdecSPECIAL_UNION_DUES = 10.00M cdecFICA_RATE = 0.06M (6%)
cdecFEDERAL_RATE = 0.15M (15%) cdecSTATE_RATE = 0.05M (5%)
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.
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 values 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;
if (intHours <= 40)
decGross = intHours * decRate;
else
decGross = (40 * decRate) + ((intHours - 40) * decRate * 1.5M);
See CS4 for information on calculating the taxes.
Check which radio button is selected for the type of union membership. Use if-else
statements to assign a the correct amount stored in the constants to a local variable.
Then subtract the taxes and the union dues amount from gross pay to get the netpay.
Count the number of employees processed, accumulate the net pay, calculate the average
net pay, and then display the summary values. All output should be formatted to two
decimal points.
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.
In addition, the employee count and total netpay accumulator should 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 CS5Form : Form
(
public CS5Form()
{
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
try
{
//Use a try-catch block to catch non-numeric values
//Get value for hours
//Get value for pay rate
//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
//Calculate taxes
//if statement to set Union Dues variable - check radio buttons
//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 exceptions for Hours and Payrate
catch (FormatException err)
{
MessageBox.Show("Hours or Payrate not numeric. " + err.Message,
"Data Entry Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
txtHours.SelectAll();
txtHours.Focus();
}
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 namespace
Submit CS5Form.cs and CS5Form.Designer.cs