In: Computer Science
C# - Visual Studio Community
1.3 In a country XYZ a government organization classifies its
employees according to categories: A and B. The salary of an
employee depends on the number of years of service, and the
category of the employee. The gross yearly salary grid is shown
below.
Category A |
Category B |
|
Years |
||
0-4 |
$ 45,000 |
$ 52,000 |
5-9 |
$ 50,000 |
$ 60,000 |
10-14 |
$ 55,000 |
$ 67,000 |
15-19 |
$ 58,000 |
$ 74,000 |
>19 |
$ 60,000 |
$ 80,000 |
If an employee earns less than $55,000, the tax rate on income is 30%. Between $55,000 and below $70,000 the rate is 35%. Above $70,000, the rate is 40%. Employees can also choose between 0%, 3%, or 5% option for their yearly pension savings as a percentage of their pay after taxes. Develop an application that will allow indicating employee category (use radio buttons), years of service (text box or list box), and chosen pension saving plan (radio buttons). The application should calculate: 1) the gross salary; 2) taxes deducted; 3) pension deduction; and 4) the net pay (all on a yearly basis).
Code
using System;
using System.Windows.Forms;
public partial class frmMain : Form
{
double[] categoryASalary = { 45000, 50000, 55000, 58000, 60000
};
double[] categoryBSalary = { 52000, 60000, 67000, 74000, 80000
};
public frmMain()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs
e)
{
double grossPay=0, taxes, pensionDeduction=0, netPay;
if (rdbCategoryA.Checked)
grossPay = categoryASalary[lstYears.SelectedIndex];
if (rdbCategoryB.Checked)
grossPay = categoryBSalary[lstYears.SelectedIndex];
taxes = calculateTax(grossPay);
if (rdbPension3.Checked)
pensionDeduction = (grossPay - taxes) * 0.03;
if(rdbPension5.Checked)
pensionDeduction = (grossPay - taxes) * 0.05;
netPay = grossPay - taxes - pensionDeduction;
lblGrossPay.Text = grossPay.ToString("C2");
lblNetPay.Text = netPay.ToString("C2");
lblPension.Text = pensionDeduction.ToString("C2");
lblTaxes.Text = taxes.ToString("C2");
}
private double calculateTax(double grossPay)
{
if (grossPay < 55000)
return grossPay * 0.3;
else if(grossPay>=55000 && grossPay<70000)
return grossPay * 0.35;
return grossPay * 0.4;
}
}
Desing
frmMain.Designer.Cs
partial class frmMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should
be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.rdbCategoryA = new System.Windows.Forms.RadioButton();
this.rdbCategoryB = new System.Windows.Forms.RadioButton();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.rdbPension5 = new System.Windows.Forms.RadioButton();
this.rdbPension0 = new System.Windows.Forms.RadioButton();
this.rdbPension3 = new System.Windows.Forms.RadioButton();
this.lstYears = new System.Windows.Forms.ListBox();
this.label1 = new System.Windows.Forms.Label();
this.btnCalculate = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.lblGrossPay = new System.Windows.Forms.Label();
this.lblTaxes = new System.Windows.Forms.Label();
this.lblPension = new System.Windows.Forms.Label();
this.lblNetPay = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.rdbCategoryB);
this.groupBox1.Controls.Add(this.rdbCategoryA);
this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans
Serif", 9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.groupBox1.Location = new System.Drawing.Point(12, 31);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(252, 63);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Choose Category";
//
// rdbCategoryA
//
this.rdbCategoryA.AutoSize = true;
this.rdbCategoryA.Location = new System.Drawing.Point(16,
29);
this.rdbCategoryA.Name = "rdbCategoryA";
this.rdbCategoryA.Size = new System.Drawing.Size(93, 19);
this.rdbCategoryA.TabIndex = 0;
this.rdbCategoryA.TabStop = true;
this.rdbCategoryA.Text = "Category A";
this.rdbCategoryA.UseVisualStyleBackColor = true;
//
// rdbCategoryB
//
this.rdbCategoryB.AutoSize = true;
this.rdbCategoryB.Location = new System.Drawing.Point(151,
29);
this.rdbCategoryB.Name = "rdbCategoryB";
this.rdbCategoryB.Size = new System.Drawing.Size(94, 19);
this.rdbCategoryB.TabIndex = 1;
this.rdbCategoryB.TabStop = true;
this.rdbCategoryB.Text = "Category B";
this.rdbCategoryB.UseVisualStyleBackColor = true;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.rdbPension3);
this.groupBox2.Controls.Add(this.rdbPension5);
this.groupBox2.Controls.Add(this.rdbPension0);
this.groupBox2.Font = new System.Drawing.Font("Microsoft Sans
Serif", 9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.groupBox2.Location = new System.Drawing.Point(12, 123);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(252, 63);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Pension savings";
//
// rdbPension5
//
this.rdbPension5.AutoSize = true;
this.rdbPension5.Location = new System.Drawing.Point(178,
29);
this.rdbPension5.Name = "rdbPension5";
this.rdbPension5.Size = new System.Drawing.Size(45, 19);
this.rdbPension5.TabIndex = 1;
this.rdbPension5.TabStop = true;
this.rdbPension5.Text = "5%";
this.rdbPension5.UseVisualStyleBackColor = true;
//
// rdbPension0
//
this.rdbPension0.AutoSize = true;
this.rdbPension0.Location = new System.Drawing.Point(16, 29);
this.rdbPension0.Name = "rdbPension0";
this.rdbPension0.Size = new System.Drawing.Size(45, 19);
this.rdbPension0.TabIndex = 0;
this.rdbPension0.TabStop = true;
this.rdbPension0.Text = "0%";
this.rdbPension0.UseVisualStyleBackColor = true;
//
// rdbPension3
//
this.rdbPension3.AutoSize = true;
this.rdbPension3.Location = new System.Drawing.Point(97, 29);
this.rdbPension3.Name = "rdbPension3";
this.rdbPension3.Size = new System.Drawing.Size(45, 19);
this.rdbPension3.TabIndex = 2;
this.rdbPension3.TabStop = true;
this.rdbPension3.Text = "3%";
this.rdbPension3.UseVisualStyleBackColor = true;
//
// lstYears
//
this.lstYears.Font = new System.Drawing.Font("Microsoft Sans
Serif", 9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lstYears.FormattingEnabled = true;
this.lstYears.ItemHeight = 15;
this.lstYears.Items.AddRange(new object[] {
"0 - 4",
"5 - 9",
"10 - 14",
"15 - 19",
">19"});
this.lstYears.Location = new System.Drawing.Point(73, 226);
this.lstYears.Name = "lstYears";
this.lstYears.Size = new System.Drawing.Size(120, 94);
this.lstYears.TabIndex = 3;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif",
9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(70, 210);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(112, 15);
this.label1.TabIndex = 4;
this.label1.Text = "Years of service,";
//
// btnCalculate
//
this.btnCalculate.Font = new System.Drawing.Font("Microsoft Sans
Serif", 9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnCalculate.Location = new System.Drawing.Point(73,
362);
this.btnCalculate.Name = "btnCalculate";
this.btnCalculate.Size = new System.Drawing.Size(120, 32);
this.btnCalculate.TabIndex = 5;
this.btnCalculate.Text = "Calculate";
this.btnCalculate.UseVisualStyleBackColor = true;
this.btnCalculate.Click += new
System.EventHandler(this.btnCalculate_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif",
9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label2.Location = new System.Drawing.Point(25, 425);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(96, 15);
this.label2.TabIndex = 6;
this.label2.Text = "Gross Salary: ";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif",
9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.Location = new System.Drawing.Point(25, 452);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(45, 15);
this.label3.TabIndex = 7;
this.label3.Text = "Taxes";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif",
9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label4.Location = new System.Drawing.Point(25, 481);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(126, 15);
this.label4.TabIndex = 8;
this.label4.Text = "Pension deduction";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif",
9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label5.Location = new System.Drawing.Point(25, 509);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(63, 15);
this.label5.TabIndex = 9;
this.label5.Text = "Net pay: ";
//
// lblGrossPay
//
this.lblGrossPay.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblGrossPay.Font = new System.Drawing.Font("Microsoft Sans
Serif", 9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblGrossPay.Location = new System.Drawing.Point(159,
421);
this.lblGrossPay.Name = "lblGrossPay";
this.lblGrossPay.Size = new System.Drawing.Size(105, 24);
this.lblGrossPay.TabIndex = 10;
//
// lblTaxes
//
this.lblTaxes.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblTaxes.Font = new System.Drawing.Font("Microsoft Sans
Serif", 9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblTaxes.Location = new System.Drawing.Point(159, 452);
this.lblTaxes.Name = "lblTaxes";
this.lblTaxes.Size = new System.Drawing.Size(105, 24);
this.lblTaxes.TabIndex = 11;
//
// lblPension
//
this.lblPension.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblPension.Font = new System.Drawing.Font("Microsoft Sans
Serif", 9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblPension.Location = new System.Drawing.Point(159,
481);
this.lblPension.Name = "lblPension";
this.lblPension.Size = new System.Drawing.Size(105, 24);
this.lblPension.TabIndex = 12;
//
// lblNetPay
//
this.lblNetPay.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblNetPay.Font = new System.Drawing.Font("Microsoft Sans
Serif", 9F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblNetPay.Location = new System.Drawing.Point(159, 509);
this.lblNetPay.Name = "lblNetPay";
this.lblNetPay.Size = new System.Drawing.Size(105, 24);
this.lblNetPay.TabIndex = 13;
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(286, 540);
this.Controls.Add(this.lblNetPay);
this.Controls.Add(this.lblPension);
this.Controls.Add(this.lblTaxes);
this.Controls.Add(this.lblGrossPay);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.btnCalculate);
this.Controls.Add(this.label1);
this.Controls.Add(this.lstYears);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "frmMain";
this.Text = "The gross yearly salary";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton rdbCategoryB;
private System.Windows.Forms.RadioButton rdbCategoryA;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.RadioButton rdbPension3;
private System.Windows.Forms.RadioButton rdbPension5;
private System.Windows.Forms.RadioButton rdbPension0;
private System.Windows.Forms.ListBox lstYears;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnCalculate;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label lblGrossPay;
private System.Windows.Forms.Label lblTaxes;
private System.Windows.Forms.Label lblPension;
private System.Windows.Forms.Label lblNetPay;
}
Output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.