Answer to Question #188599 in C# for santhosh asrith

Question #188599

The contract Employee class will have Perks as an additional property. The PermanentEmployee will have NoOfLeaves and ProvidendFund Properties.

1. Create these two classes by inheriting from the Employee class.

2. Override the GetSalary Method in these two classes. For Contract employee the new salary will be Salary + Perks. For Permanent Employee the new salary will be Salary – Providend Fund.

3. Create a console application to use these classes. Create a Menu driven application to select the Type of employee. Based on the user selection create the object and accept the details from the user. Also display the salary of the Employee.

4. As we only need to create instance of Contract Employee and Permanent Employee classes, Convert the Employee class to Abstract class. Also make GetSalary method Abstract in the Base class.


1
Expert's answer
2021-05-03T10:26:59-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace C_SHARP
{
    class Program
    {


        abstract  class Employee {
            public double Salary { get; set; }
            public Employee() { }
            public Employee(double salary) {
                this.Salary = salary;
            }
            public abstract double GetSalary();
            public abstract void display(); 
        }


        class ContractEmployee:Employee {
            public double Perks{ get; set; }
            public ContractEmployee() { }
            public ContractEmployee(double perks,double salary)
                : base(salary)
            {
                this.Perks = perks;
            }
            /// <summary>
            ///  For Contract employee the new salary will be Salary + Perks.
            /// </summary>
            /// <returns></returns>
            public override double GetSalary() {
                return Salary + Perks;
            }
            public override void display()
            {
                Console.WriteLine("Contract employee");
                Console.WriteLine("Salary: {0}", Salary.ToString("C"));
                Console.WriteLine("Perks: {0}", Perks.ToString("C"));
            }
        }
        class PermanentEmployee : Employee
        {
            public int NoOfLeaves { get; set; }
            public double ProvidendFund{ get; set; }
            public PermanentEmployee() { }
            public PermanentEmployee(int noOfLeaves, double providendFund, double salary)
                : base(salary)
            {
                this.NoOfLeaves = noOfLeaves;
                this.ProvidendFund= providendFund;
            }
            /// <summary>
            /// For Permanent Employee the new salary will be Salary – Providend Fund.
            /// </summary>
            /// <returns></returns>
            public override double GetSalary()
            {
                return Salary - ProvidendFund;
            }
            public override void display()
            {
                Console.WriteLine("Permanent employee");
                Console.WriteLine("Salary: {0}", Salary.ToString("C"));
                Console.WriteLine("No of leaves: {0}", NoOfLeaves);
                Console.WriteLine("Providend fund: {0}", ProvidendFund.ToString("C"));
            }
        }






        static void Main(string[] args)
        {


            //create instance of Contract Employee and Permanent Employee classes
            Employee employee=null;
            int employeeType=-1;
            while (employeeType != 3) {
                Console.WriteLine("1. Contract Employee");
                Console.WriteLine("2. Permanent Employee");
                Console.WriteLine("3. Exit");
                Console.Write("Select the type of employee: ");
                employeeType = int.Parse(Console.ReadLine());
                if (employeeType == 1) {
                    employee = new ContractEmployee();
                    Console.Write("Enter the salary of contract employee: ");
                    employee.Salary = double.Parse(Console.ReadLine());
                    Console.Write("Enter the perks of contract employee: ");
                    ((ContractEmployee)employee).Perks = double.Parse(Console.ReadLine());
                    employee.display();
                    Console.WriteLine("Salary: {0}", employee.GetSalary().ToString("C"));
                }
                else if (employeeType == 2)
                {
                    employee = new PermanentEmployee();
                    Console.Write("Enter salary of permanent employee: ");
                    employee.Salary = double.Parse(Console.ReadLine());
                    Console.Write("Enter the number of leaves of permanent employee: ");
                    ((PermanentEmployee)employee).NoOfLeaves =int.Parse(Console.ReadLine());
                    Console.Write("Enter the providend fund of permanent employee: ");
                    ((PermanentEmployee)employee).ProvidendFund= double.Parse(Console.ReadLine());
                    employee.display();
                    Console.WriteLine("Salary: {0}", employee.GetSalary().ToString("C"));
                }
                else if (employeeType == 3) { 
                //exit
                }
                else
                {
                    Console.WriteLine("Select correct employee.");
                }
            }


        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS