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 } }
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; } }