Answer to Question #306582 in C# for zubi

Question #306582

 Create a class called Employee that includes three pieces of information as data members, a name (type string), ID (type integer) and a monthly salary (type integer). Employee class should have a constructor that initializes the three data members. And employee class should have a destructor which shows message when object of the class is destroyed from the memory. Provide a “setData” and a “getData” function for each data member. If the monthly salary is not positive, set it to -1.

Write a test program that demonstrates class Employee’s functionalities. Create two Employee objects and display each object’s yearly salary after deducting 4% tax.

Note...Its C# Question


1
Expert's answer
2022-03-05T13:00:39-0500


using System;
using System.Collections.Generic;
using System.Globalization;


namespace App
{
    class Employee
    {
        private string name;
        private int ID;
        private int monthlySalary;


        public Employee(string name, int ID, int monthlySalary)
        {
            setName(name);
            setID(ID);
            setMonthlySalary(monthlySalary);
        }
        public void setName(string name)
        {
            this.name = name;
        }


        public string getName()
        {
            return name;
        }


        public void setID(int ID)
        {
            this.ID = ID;
        }


        public int getID()
        {
            return ID;
        }
        public void setMonthlySalary(int monthlySalary)
        {
            if (monthlySalary >= 0)
            {
                this.monthlySalary = monthlySalary;
            }
            else
            {
                this.monthlySalary = -1;
            }


        }


        public int getMonthlySalary()
        {
            return monthlySalary;
        }


        public double yearlySalaryAfterDeductingTax()
        {
            return monthlySalary-monthlySalary*0.04;
        }
    }


    class Program{


        static void Main(string[] args)
        {
            Employee Employee1 = new Employee("Peter",45565,2000);
            Employee Employee2 = new Employee("Mary", 78452, 8755);
            Console.WriteLine("The yearly salary after deducting 4% tax for Employee 1 is: {0} ", Employee1.yearlySalaryAfterDeductingTax());
            Console.WriteLine("The yearly salary after deducting 4% tax for Employee 1 is: {0} ", Employee2.yearlySalaryAfterDeductingTax());


            
            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