-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOPA14August.cs
More file actions
193 lines (176 loc) · 7.13 KB
/
OPA14August.cs
File metadata and controls
193 lines (176 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//Author: Vishva Patel
using System;
using System.Collections.Generic;
namespace OPA14thAUG
{
class OPA14August
{
static void Main(string[] args)
{
EmployeeManager manager = new EmployeeManager(); //creating the oject of Employee Manager Class
manager.AddEmployee("Ravi", "1.4", "Masters");
manager.AddEmployee("Ram", "2.3", "Degree");
manager.AddEmployee("Rachel", "1.0", "Masters");
//ORIGINAL PROGRAM BEGINS
int choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
//VIEW THE EMPLOYEES
List<Employee> emp = manager.ViewEmployees();
if(emp == null)
{
Console.WriteLine("No employees present");
}
else
{
foreach (var em in emp)
{
string[] experinece = em.experience.Split('.'); //Splitting years and month
int year = Convert.ToInt16(experinece[0]); //Extract Years
int month = Convert.ToInt16(experinece[1]); //Extract Months
Console.WriteLine($"{em.empId}: {em.Name}, experience:{year}y{month}m, gross = {em.grossalary}, " +
$"net = {em.netsalary}");
}
}
break;
//ADDING EMPLOYEES
case 2:
string name = Console.ReadLine();
string exp = Console.ReadLine();
string quali = Console.ReadLine();
Employee e = null;
if(quali == "Degree" || quali == "Masters")
{
if (!exp.Contains('.'))
{
Console.WriteLine("Invalid format!");
}
if (e == null)
{
Console.WriteLine("Employee already exists");
}
else
{
Console.WriteLine($"Name: {e.Name} \n Id: {e.empId} \n Experience: {e.experience} \n Qualification: {e.qualification}" +
$"\n BasicPay: {e.basicsalary} \n Gross Pay: {e.grossalary} \n PF: {e.Pf} \n Tax: {e.tax} \n Net pay: {e.netsalary}");
}
}
else
{
Console.WriteLine("Invalid Qualification");
}
break;
}
}
}
class Employee
{
public int empId { get; set; } //Employee Id
public string Name { get; set; } //Employee Name
public string experience { get; set; } //Employee Experience
public string qualification { get; set; } //Employee Qalification
public double grossalary { get; set; }
public double basicsalary { get; set; }
public double Pf { get; set; } //Employee providend fund
public double tax { get; set; }
public double netsalary { get; set; }
//This constructor when called will create an entry adding into the list
public Employee(int id, string nme, string exp, string quali, double gs, double bs,double pfund, double tx, double netsal)
{
empId = id;
Name = nme;
experience = exp;
qualification = quali;
grossalary = gs;
Pf = pfund;
tax = tx;
basicsalary = bs;
netsalary = netsal;
}
}
class EmployeeManager
{
List<Employee> employees = new List<Employee>(); //Creating the list of employees
public static int Id = 1001; //Getting the autogenerated ID
//Calculating Gross Salary
public double CalculateGross(string exp,string quali)
{
string[] experinece = exp.Split('.'); //Splitting years and month
int year = Convert.ToInt16(experinece[0]); //Extract Years
int month = Convert.ToInt16(experinece[1]); //Extract Months
if (quali == "Degree" && year == 1)
{
return month == 0 ? 250000 : 300000; //Exactly One Year or less than 2 year
}
else if (quali == "Degree" && year > 1)
{
return month > 0 ? 250000 + 50000 * (year) : 250000 + 50000 * (year - 1); //Greater and equal to 2 years experience
}
else
{
//qualification is masters
if (year == 1)
{
return month > 0? 315000: 300000; //equal to 1 year or more but less than 2 years
}
else
{
return year > 1 && month > 0 ? 300000 + 15000 * (year) : 300000 + 15000 * (year - 1); //Greater and equal to 2 years experience
}
}
}
public double CalculateTax(double gs)
{
if (gs < 300000)
{
return 0; //Zero tax
}
else if(gs > 300000 && gs < 500001)
{
return 0.1 * gs; //10% tax
}
else if(gs > 500000 && gs < 800001)
{
return 0.2 * gs; //20% tax
}
else
{
return 0.3 * gs; //30% tax
}
}
public List<Employee> ViewEmployees()
{
if (employees == null)
{
return null; //If list is empty
}
else
{
return employees; //return the list of employees
}
}
public Employee AddEmployee(string empname, string experience,string quali)
{
EmployeeManager m = new EmployeeManager(); //Creating the employee manager
double gs = m.CalculateGross(experience, quali); //Calculating gross salary
double tax = m.CalculateTax(gs); //Calculating tax on gross salary
double bs = 0.4 * gs; //Basic salary
double pfund = 0.12 * bs; //Providend Fund salary
double ns = gs - (pfund + tax); //Net salary
Employee e = new Employee(Id, empname, experience, quali, gs,bs , pfund, tax, ns); //Creating an employee object to add to list
//Checking for existing employee
if (employees.Contains(e))
{
Id--; //Deleting the Id alotted
return null; //returning null
}
else
{
employees.Add(e); //Adding the employee
Id++; //Incrementing the Id
return e; //returning the employee object
}
}
}
}