The document outlines a C# program that defines an Employee class with private properties for Id, Name, and DepartmentName, along with methods to retrieve these properties and an event that triggers when any method is called. It also includes a Program class that prompts the user for employee details, creates an Employee object, and allows for updating the employee's properties through overloaded methods. The program displays the employee's details before and after updates, demonstrating the functionality of the Employee class and its methods.
The document outlines a C# program that defines an Employee class with private properties for Id, Name, and DepartmentName, along with methods to retrieve these properties and an event that triggers when any method is called. It also includes a Program class that prompts the user for employee details, creates an Employee object, and allows for updating the employee's properties through overloaded methods. The program displays the employee's details before and after updates, demonstrating the functionality of the Employee class and its methods.
Write a C# program that satisfies the below requirements
1. Create a class called Employee
It has three private properties called Id, Name, DepartmentName
Its constructor should accept all of these three properties while creating an object. It should have three methods that individually returns the above properties (i.e. GetId(), GetName(), GetDepartmentName())
2. Create a Program that accepts details from the user
It should ask the user for Id, Name, DepartmentName
After getting details from the user create an object of the Employee class with provided details. After creating an object print all three properties one by one using the above-created methods.
3. Create an event in Employee Class which is fired when any of the
class’ methods are being called and outputs a message (i.e. “GetName() method called”)] 4. Create 3 overloaded methods that allow updating any of the Employee property (Id, Name, DepartmentName) Program.cs using System;
class Program { static void Main() { // Taking user input for Employee details Console.Write("Enter Employee Id: "); int id = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Employee Name: ");
string name = Console.ReadLine();
Console.Write("Enter Department Name: ");
string department = Console.ReadLine();
// Creating Employee object
Employee employee = new Employee(id, name, department);
// Method Overloading to Update Employee Properties
// Overloaded method to update Id
public void UpdateEmployee(int id) { Id = id; Console.WriteLine("Id updated successfully."); } // Overloaded method to update Name public void UpdateEmployee(string name) { Name = name; Console.WriteLine("Name updated successfully."); }
// Overloaded method to update DepartmentName
public void UpdateEmployee(string departmentName, int dummy) // Dummy parameter to differentiate { DepartmentName = departmentName; Console.WriteLine("Department Name updated successfully."); }