This program will be used by employees to determine what their weekly net pay wo
ID: 3673397 • Letter: T
Question
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.
Finished Program:
Requirements:
Set the Text of the form to the assignment number and 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.
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).
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.
Pseudocode for calculate button:
CS4 by Your Name Pay Calculator Hours Worked 45 Pay Rate 15.00 Gross Pay: FICA Tax: State Tax: Federal Tax: Union Dues Net Pay $675.00 $40.50 $33.75 $101.25 $10.00 $489.50 Totals $650.63 Total Net Pay Employee Count: Average Net Pay Calculate $325.31 Clear Form ExitExplanation / Answer
Please find below the CS# program to calculate the pay:
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)
{
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.