In this assignment, the previously completed project (CS4 Pay Calculator) will b
ID: 3708041 • Letter: I
Question
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.
Add a Group Box with the Radio Buttons inside.
Go to the Properties pane for each Radio Button and set the "Checked" property to "false" for each of them
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 any method you want (recommend to 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.
Check which of the union membership radio buttons is selected to determine the amount to deduct. Recommended to use if-else statements to assign the correct amount stored in the constants to a local variable (decUnionDues).
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:
The Clear Form button is used to clear the two input text boxes, all of the labels used to display the results of the calculations/summary totals, and deselect all of the radio buttons (setting their Chcked property to False)
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.
Grading Requirements (minor)
Set the Text of the form to the assignment number and your name (CS5 Your Name)..
The form objects (group boxes, labels, text boxes, and buttons) must all be formatted the same as the Interface Sample above.
Output must be formatted correctly (numerical, currency, etc.)
None of the radio buttons can be selected when the program is first activated
Include the two image icons (the ones you downloaded earlier) on the form
Grading Requirements (core)
The Calculate button must return correct values
The Clear Form button must completely clear all the values in the form, including resetting the running totals (employe count, total net pay) for the next calculation, as well as resetting the radio buttons so that none are selected.
The Exit button must exit the form
The radio buttons must accurately determine the amount of the Union Dues.
Error message must be generated when incorrect data input is entered: hours worked and pay rate must only be allowed to be entered as a decimal/floating point. Do not allow a runtime error to be triggered. Do not allow the calculation to proceed
Error message must be generated if the rate is outside the $10 - $15 range, or the hours outside the 1 - 50 range. Do not allow the calculation to proceed.
Error message must be generated if user doesn't select a radio button. Do not allow a runtime error to be triggered. Do not allow the calculation to proceed.
** This is the code I have from CS4, the previous assignment. Need help adding the above.
namespace CS4
{
public partial class frmCS4 : Form
{
public frmCS4()
{
InitializeComponent();
}
private decimal decGross;
private decimal decFica;
private decimal decFederal;
private decimal decState;
private decimal decNetPay;
decimal decAverageNetPay;
private decimal decPayRate;
int cintEmployeeCount;
int intHoursWorked;
decimal cdecTotalNetPay;
const decimal cdecFICA_RATE = 0.06M;
const decimal cdecFEDERAL_RATE = 0.15M;
const decimal cdecSTATE_RATE = 0.05M;
const decimal cdecUNION_DUES = 10.00M;
private void btnCalculate_Click(object sender, EventArgs e)
{
try
{
intHoursWorked = int.Parse(txtHoursWorked.Text);
try
{
decPayRate = decimal.Parse(txtPayRate.Text);
decGross = intHoursWorked * decPayRate;
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;
lblGrossPay.Text = decGross.ToString("C");
lblFICATax.Text = decFica.ToString("C");
lblFederalTax.Text = decFederal.ToString("C");
lblStateTax.Text = decState.ToString("C");
lblNetPay.Text = decNetPay.ToString("C");
lblAverageNetPay.Text = decAverageNetPay.ToString("C");
lblEmployeeCount.Text = cintEmployeeCount.ToString("N0");
lblTotalNetPay.Text = cdecTotalNetPay.ToString("C");
lblUnionDues.Text = cdecUNION_DUES.ToString("C");
}
catch (FormatException err)
{
MessageBox.Show("Pay rate must be numeric. " + err.Message,
"Data entry error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
txtPayRate.SelectAll();
txtPayRate.Focus();
}
}
catch (FormatException err)
{
MessageBox.Show("Hours worked must be numeric. " + err.Message,
"Data entry error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
txtHoursWorked.SelectAll();
txtHoursWorked.Focus();
}
catch (Exception err)
{
MessageBox.Show("Unexpected Error: " + err.Message);
}
}
private void btnClear_Click(object sender, EventArgs e)
{
txtHoursWorked.Clear();
txtPayRate.Clear();
lblGrossPay.Text = "";
lblFICATax.Text = "";
lblFederalTax.Text = "";
lblStateTax.Text = "";
lblUnionDues.Text = "";
lblNetPay.Text = "";
lblEmployeeCount.Text = "";
lblAverageNetPay.Text = "";
lblTotalNetPay.Text = "";
cdecTotalNetPay = 0;
cintEmployeeCount = 0;
decAverageNetPay = 0;
txtHoursWorked.Focus();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Explanation / Answer
CS+ PROGRAMING CODE:
namespace CS4
{
public partial class frmCS4: Form
{
public frmCS4()
{
InitializeComponent();
}
// Declare class-level variables and constants
// Class variables are initialized to zero when declare
private decimal decGross;
private decimal decFica;
private decimal decFederal;
private decimal decState;
private decimal decNetpay;
private decimal decAverageNet;
int cintEmployeeCount;
decimal cdecTotalNetpay;
const decimal cdecFICA_RATE = 0.06M;
const decimal cdecFEDERAL_RATE = 0.15M;
const decimal cdecSTATE_RATE = 0.05M;
const decimal cdecUNION_DUES = 10.00M;
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
// Use Clear or null string "" for TextBoxes, but
// only use null string "" for Labels
txtHours.Clear(); // Clear
txtPayRate.Clear();
lblGross.Text = "";
lblFica.Text = "";
lblState.Text = "";
lblFederal.Text = "";
lblUnion.Text = "";
lblNet.Text = "";
lblTotalNet.Text = "";
lblEmployee.Text = "";
lblAverage.Text = "";
//Reset Accumulators
cdecTotalNetpay = 0;
cintEmployeeCount = 0;
cdecAverageNetPay = 0;
txtHours.Focus();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
// Input
// Use nested try-catch blocks to get input values
try
{
// Get hours worked from textbox
cintEmployeeCount = int.Parse(txtHours.Text);
intHours = int.Parse(txtHours.Text);
try
{
// Get pay rate from textbox
cdecTotalNetpay = decimal.Parse(txtPayRate.Text);
decRate = decimal.Parse(txtPayRate.Text);
// Calculate gross amount
decGross = intHours * decRate;
// Calculate taxes
decFica = decGross * cdecFICA_RATE;
decFederal = decGross * cdecFEDERAL_RATE;
decState = decGross * cdecSTATE_RATE;
// Calculate net pay
decNetpay = decGross - (decFica + decFederal + decState + cdecUNION_DUES);
// Accumulate summary values
// Calculate average net pay
cdecTotalNetpay += decNetpay;
cintEmployeeCount += 1;
decAverageNet = cdecTotalNetpay / cintEmployeeCount;
//Display results of calculations and summary values
lblEmployee.Text = intHours.ToString("N0"); //Test, will delete
txtHours.Text = cintEmployeeCount.ToString("N0");
txtPayRate.Text = decRate.ToString("C");
lblGross.Text = decGross.ToString("C");
lblFica.Text = decFica.ToString("C");
lblState.Text = decState.ToString("C");
lblFederal.Text = decFederal.ToString("C");
lblNet.Text = decNetpay.ToString("C");
lblAverage.Text = decAverageNet.ToString("C");
lblEmployee.Text = cintEmployeeCount.ToString("N0");
lblTotalNet.Text = cdecTotalNetpay.ToString("C");
lblUnion.Text = cdecUNION_DUES.ToString("C");
}
catch (FormatException err)
{
MessageBox.Show("Pay Rate must be numeric. " + err.Message,
"Data Entry Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
txtPayRate.SelectAll();
txtPayRate.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);
}
}
private void txtHours_TextChanged(object sender, EventArgs e)
{
}
private void txtPayRate_TextChanged(object sender, EventArgs e)
{
}
private void frmCS4_Load(object sender, EventArgs e)
{
}//end method
public int intHours { get; set; }
public decimal cdecAverageNetPay { get; set; }
public decimal decRate { get; set; }
public void lblUnion_Click(object sender, EventArgs e)
{
}
private void lblGross_Click(object sender, EventArgs e)
{
}
private void lblFica_Click(object sender, EventArgs e)
{
}
private void lblState_Click(object sender, EventArgs e)
{
}
private void lblFederal_Click(object sender, EventArgs e)
{
}
private void lblTotalNet_Click(object sender, EventArgs e)
{
}
}
}