using System;
class Employee
{
public string Name { get; set; }
public int EmployeeID { get; set; }
public double Salary { get; protected set; }
public Employee(string name, int id)
{
Name = name;
EmployeeID = id;
}
public virtual void DisplayDetails()
{
Console.WriteLine("Employee ID: " + EmployeeID);
Console.WriteLine("Name: " + Name);
Console.WriteLine("Salary: " + Salary);
}
}
class FullTimeEmployee : Employee
{
public double BasicSalary { get; set; }
public int NumberOfDays { get; set; }
public double HRA { get; set; }
public double DA { get; set; }
public FullTimeEmployee(string name, int id, double basicSalary, int numberOfDays, double hra, double da)
: base(name, id)
{
BasicSalary = basicSalary;
NumberOfDays = numberOfDays;
HRA = hra;
DA = da;
}
public void CalculateSalary()
{
Salary = (BasicSalary * NumberOfDays) + HRA + DA;
}
public override void DisplayDetails()
{
base.DisplayDetails();
Console.WriteLine("Employee Type: Full-Time");
Console.WriteLine("Basic Salary: " + BasicSalary);
Console.WriteLine("Number of Days: " + NumberOfDays);
Console.WriteLine("HRA: " + HRA);
Console.WriteLine("DA: " + DA);
Console.WriteLine();
}
}
class PartTimeEmployee : Employee
{
public double DailyWages { get; set; }
public int NumberOfDays { get; set; }
public PartTimeEmployee(string name, int id, double dailyWages, int numberOfDays)
: base(name, id)
{
DailyWages = dailyWages;
NumberOfDays = numberOfDays;
}
public void CalculateSalary()
{
Salary = DailyWages * NumberOfDays;
}
public override void DisplayDetails()
{
base.DisplayDetails();
Console.WriteLine("Employee Type: Part-Time");
Console.WriteLine("Daily Wages: " + DailyWages);
Console.WriteLine("Number of Days: " + NumberOfDays);
Console.WriteLine();
}
}
class Program
{
static void Main()
{
FullTimeEmployee fte = new FullTimeEmployee("Abhi", 101, 1000, 20, 500, 300);
fte.CalculateSalary();
fte.DisplayDetails();
PartTimeEmployee pte = new PartTimeEmployee("Abh", 102, 500, 15);
pte.CalculateSalary();
pte.DisplayDetails();
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter