Answer to Question #259334 in C# for Zooo

Question #259334

Create a class named Employee which will have several derived one which are



IT Executive, HR Manager, Market Analyst and Part Timer. All the employess



must have name, id (format of id E-0001,E-0002 etc.), name, date of birth,



joining date[all the dates need to be of custom type], blood group, address



(thana, home district, phone no) and monthly salary.IT Executive has project



bonus, HR Manager has KPI and Market Analyst has Commission as extra income



per month; Part timer doesn't have anyting extra.




Create at least one object for each and individual type of empolyee and show



all of their information including total income for everyone from a single



method. For initializing the object use parameterized constructor.Create



necessary methods, properties, constructors also use proper object oriented



approach, you know only getting output is not our target. To calculate the



total income you can create a separate method.

1
Expert's answer
2021-10-31T12:07:19-0400
using System;
using System.Collections.Generic;


namespace App
{


    abstract class Employee
    {
        private string id;// (format of id E-0001,E-0002 etc.);


        public string Id
        {
            get { return id; }
            set { id = value; }
        }
        private string name;


        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private string dateBirth;


        public string DateBirth
        {
            get { return dateBirth; }
            set { dateBirth = value; }
        }
        private string joiningDate; //[all the dates need to be of custom type];


        public string JoiningDate
        {
            get { return joiningDate; }
            set { joiningDate = value; }
        }
        private string bloodGroup;


        public string BloodGroup
        {
            get { return bloodGroup; }
            set { bloodGroup = value; }
        }
        private string address;//(thana, home district, phone no)


        public string Address
        {
            get { return address; }
            set { address = value; }
        }
        private double monthlySalary;


        public double MonthlySalary
        {
            get { return monthlySalary; }
            set { monthlySalary = value; }
        }


        public Employee() { }


        public Employee(string id, string name, string dateBirth, string joiningDate, string bloodGroup, string address, double monthlySalary)
        {
            this.id = id;
            this.name = name;
            this.dateBirth = dateBirth;
            this.joiningDate = joiningDate;
            this.bloodGroup = bloodGroup;
            this.address = address;
            this.monthlySalary = monthlySalary;
        }


        public virtual double calculateTotalIncome()
        {
            return this.monthlySalary;
        }


        public override string ToString()
        {
            return "Id: " + id+Environment.NewLine+
                "Name: " + name + Environment.NewLine +
                "Date of birth: " + dateBirth + Environment.NewLine +
                "joiningDate: " + joiningDate + Environment.NewLine +
                "Blood group: " + bloodGroup + Environment.NewLine +
                "Address: " + address + Environment.NewLine +
                "Monthly salary: " + monthlySalary.ToString() + Environment.NewLine;
        }


    }


    class ITExecutive : Employee
    {
        //y.IT Executive has project bonus
        private double projectBonus;


        public double ProjectBonus
        {
            get { return projectBonus; }
            set { projectBonus = value; }
        }
        public ITExecutive(string id, string name, string dateBirth, string joiningDate,
           string bloodGroup, string address, double monthlySalary, double projectBonus)
            : base(id, name, dateBirth, joiningDate, bloodGroup, address, monthlySalary)
        {
            this.projectBonus = projectBonus;
        }




        public override double calculateTotalIncome()
        {
            return this.MonthlySalary + this.projectBonus;
        }


        public override string ToString()
        {
            return "IT Executive Employee" + Environment.NewLine +
                base.ToString()+
                  "Project bonus: " + projectBonus.ToString() + Environment.NewLine;
        }


    }
    class HRManager : Employee
    {
        //HR Manager has KPI
        private double KPI;
        public HRManager(string id, string name, string dateBirth, string joiningDate,
            string bloodGroup, string address, double monthlySalary, double KPI)
            : base(id, name, dateBirth, joiningDate, bloodGroup, address, monthlySalary)
        {
            this.KPI = KPI;
        }


        public override double calculateTotalIncome()
        {
            return this.MonthlySalary + this.KPI;
        }
        public override string ToString()
        {
            return "HR Manager Employee" + Environment.NewLine +
                    base.ToString() +
                  "KPI: " + KPI.ToString() + Environment.NewLine;
        }
    }
    class MarketAnalyst : Employee
    {
        //Market Analyst has Commission as extra income per month;
        private double commission;
        public MarketAnalyst(string id, string name, string dateBirth, string joiningDate,
            string bloodGroup, string address, double monthlySalary, double commission)
            : base(id, name, dateBirth, joiningDate, bloodGroup, address, monthlySalary)
        {
            this.commission = commission;
        }
        public override double calculateTotalIncome()
        {
            return this.MonthlySalary + this.commission * this.MonthlySalary;
        }
        public override string ToString()
        {
            return "Market Analyst Employee" + Environment.NewLine + 
                base.ToString() +
                  "Commission: " + commission.ToString() + Environment.NewLine;
        }
    }


    class PartTimer : Employee
    {


        public PartTimer(string id, string name, string dateBirth, string joiningDate,
            string bloodGroup, string address, double monthlySalary)
            : base(id, name, dateBirth, joiningDate, bloodGroup, address, monthlySalary)
        {


        }
        public override string ToString()
        {
            return "Part Timer Employee"+ Environment.NewLine+
                 base.ToString();
        }
    }




    class Program
    {


        static void Main(string[] args)
        {
            //Create at least one object for each and individual type of empolyee and show
            //all of their information including total income for everyone from a single method. 
            List<Employee> Employees = new List<Employee>();
            //id, string name, string dateBirth, string joiningDate, string bloodGroup, string address, double monthlySalary
            Employees.Add(new ITExecutive("E-0001", "Peter Clark", "12.12.1990", "08.09.2011","II","Address 125",2565,250));
            Employees.Add(new HRManager("E-0002", "Mary Smith", "12.10.1991", "01.05.2010", "III", "Address 124", 3500, 1550));
            Employees.Add(new MarketAnalyst("E-0003", "Mike Smith", "10.10.1995", "01.05.2015", "I", "Address 129", 1200, 150));
            Employees.Add(new PartTimer("E-0004", "Julia Peterson", "10.11.1994", "01.01.2014", "IV", "Address 1598", 2200));
            //For initializing the object use parameterized constructor.Create
            //necessary methods, properties, constructors also use proper object oriented
            //approach, you know only getting output is not our target. To calculate the total 
            //income you can create a separate method.
            for (int i = 0; i < Employees.Count; i++) {
                Console.Write(Employees[i].ToString());
                Console.WriteLine("Total income: " + Employees[i].calculateTotalIncome());
                Console.WriteLine();
            }






                Console.ReadLine();
        }
    }
}

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