Question: Project Build a Windows application that allows users to input basic employee information to calculate the employee's pay amount. You should also display totals back
Project
Build a Windows application that allows users to input basic employee information to calculate the employee's pay amount.
You should also display totals back to the user for the following information:
Create a form that allows the user to enter the following information. (Hint: If you want to store properties and behaviors together, how would you accomplish this?)
Name (First and Last)
Hourly Rate
Hours Worked in the Pay Period
The user should be able to input this information for each employee. However, the application won't perform the calculations until the user enters Submit. (Hint: How would you store these objects?)
Once the user clicks the "Submit" button, the application calculates the information for all employees and outputs the following information back to the user for each employee. (Hint: What type of loop would be best to iterate through multiple objects of the same type?)
Name
Gross Pay
Net Pay
SS Withheld
Medicare Withheld
State Income Tax Withheld
Federal Income Tax Withheld
Total Gross Pay
Total Net Pay
Total SS Withheld
Total Medicare Withheld
Total State Income Tax Withheld
Total Federal Income Tax Withheld
You can use any display format you would like. You can output the required information to a large label or textbox, or you can research advanced techniques such as grids. Since you haven't used any of the advanced display features in Windows forms, you are not expected to use them. Regardless of the format you choose, make sure the individual fields are correctly formatted. For example, if the field contains currency information, you must display it using a dollar sign and the correct decimal places.
Use the following calculations.
Calculate Medicare at 1.45%. Calculate Social Security at 6.2%.
In addition, include the following information in your calculations.
If an employee makes between 0 and $500, the state tax rate is 2%, and the federal tax rate is 5%.
If an employee makes between $500 and $999.99, the state tax rate is 4%, and the federal tax rate is 10%.
If an employee makes between $1,000 and $1,499.99, the state tax rate is 6%, and the federal tax rate is 15%.
If an employee makes between $1,500 and $1,999.99, the state tax rate is 6%, and the federal tax rate is 20%.
If an employee makes between $2,000 and $2,999.99, the state tax rate is 6%, and the federal tax rate is 25%.
If an employee makes more than $3,000, the state tax rate is 6%, and the federal tax rate is 30%.
Example
An employee makes $25 per hour and works 80 hours for the pay period. This means the gross pay is $2,000.
The federal tax withheld is $2,000 x .25 = $500.
The state tax withheld is $2,000 x .06 = $120.
The social security withheld is $2,000 x .062 = $124.
The Medicare withheld is $2,000 x .0145 = $29.
The total net for the employee is $2,000 - $500 - $120 - $124 - $29 = $1,227.
You need this information for each employee the user enters.
Your application should use good design principles, be user-friendly, prevent errors from occurring, and provide useful feedback if a user enters incorrect information.
Question: What am I doing wrong? The net pay is higher than the gross pay which makes no sense.
code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace Final_Project { public partial class Form1 : Form {
public List
public double totalGross = 0; public double totalNetPay = 0; public double totalSSWithheld = 0; public double totalMedicareWithHeld = 0; public double totalStateIncomeTaxWithheld = 0;
public double totalFederalIncomeTaxWithheld = 0;
public Form1() { InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
for (int i = 0; i < list.Count; i++) { richTextBox1.Text +=" Name: " + list[i].Name + " Gross Pay: $" + list[i].GrossPay + " Net Pay: $" + list[i].NetPay + " SS Witheld: $" + list[i].SSWithheld + " Medicare Witheld: $" + list[i].MedicareWithheld + " State Income Tax Witheld: $" + list[i].StateIncomeTaxWithheld + " Federal Income Tax Witheld: $" + list[i].FederalIncomeTaxWithheld; richTextBox1.Text += " "; }
richTextBox1.Text += " ";
richTextBox1.Text += " Total Gross Pay: $"+ totalGross + " Total Net Pay: $" + totalNetPay + " Total SS Witheld: $" + totalSSWithheld + " Total Medicare Witheld: $" + totalMedicareWithHeld + " Total State Income Tax Witheld: $" + totalStateIncomeTaxWithheld + " Total Federal Income Tax Witheld: $" + totalFederalIncomeTaxWithheld +" ";
}
private void button2_Click(object sender, EventArgs e) {
Employee emp = new Employee(); emp.Name = textBox1.Text + textBox2.Text; emp.GrossPay = (Convert.ToDouble(textBox3.Text) * Convert.ToDouble(textBox4.Text));
emp.MedicareWithheld = emp.GrossPay * 0.0145; emp.SSWithheld = emp.GrossPay * 0.062;
if (emp.GrossPay <= 500 && emp.GrossPay >= 0) { emp.StateIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.02); emp.FederalIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.05); } else if (emp.GrossPay <= 999.99 && emp.GrossPay >= 500) { emp.StateIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.04); emp.FederalIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.10); } else if (emp.GrossPay <= 1499.99 && emp.GrossPay >= 1000) { emp.StateIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.06); emp.FederalIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.15); } else if (emp.GrossPay <= 1999.99 && emp.GrossPay >= 1500) { emp.StateIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.06); emp.FederalIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.20); } else if (emp.GrossPay < 2999.99 && emp.GrossPay >= 2000) { emp.StateIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.06); emp.FederalIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.25); } else if (emp.GrossPay > 3000) { emp.StateIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.06); emp.FederalIncomeTaxWithheld = emp.GrossPay - (emp.GrossPay * 0.30); }
emp.NetPay = emp.GrossPay - (emp.MedicareWithheld - emp.SSWithheld - emp.StateIncomeTaxWithheld - emp.FederalIncomeTaxWithheld);
list.Add(emp);
totalFederalIncomeTaxWithheld += emp.FederalIncomeTaxWithheld;
totalGross += emp.GrossPay;
totalMedicareWithHeld += emp.MedicareWithheld;
totalNetPay += emp.NetPay;
totalSSWithheld += emp.SSWithheld;
totalStateIncomeTaxWithheld += emp.StateIncomeTaxWithheld;
textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); }
private void label1_Click(object sender, EventArgs e) {
}
private void label4_Click(object sender, EventArgs e) {
}
private void textBox5_TextChanged(object sender, EventArgs e) {
}
private void textBox1_TextChanged(object sender, EventArgs e) {
} }
public class Employee { public string Name;
public double GrossPay;
public double NetPay;
public double SSWithheld;
public double MedicareWithheld;
public double StateIncomeTaxWithheld;
public double FederalIncomeTaxWithheld; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
