Answer to Question #331870 in C# for Macky

Question #331870

Programming


a. Create class name Employee


b. add the attributes: firstName, LastName, MiddleName, Age, Company,Salary and


IDNumber


c. create a getters and setter for the class


d. add constructors (with and without parameters)


e. add function in your class name it DisplayInfo to display all details of the employee


f. add a function name it SalWithVat, to calculate the salary with 12% tax deduction.


g. Create main class to test your Class

1
Expert's answer
2022-04-21T18:06:34-0400


//On main I add an example but we can add many object data
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//define class
class Employee
{
        private string FirstName { get; set; }
        public string LastName { get; set; }
        public string MiddleName { get; set; }
        public int Age { get; set; }
        public string Company { get; set; }
        public double Salary { get; set; }
        public int IDNumber { get; set; }
   public Employee()//default constructor
        {
            FirstName = "-";
            LastName = "-";
            MiddleName = "-";
            Age = 17;
            Company = "Google";
            Salary = 1000;
            IDNumber = 1;
        }
        public Employee(string f,string l,string m,int ol,string com,double
            sal,int id)//Constructor with parametres
        {
            FirstName = f;
            LastName = l;
            MiddleName = m;
            Age = ol;
            Company = com;
            Salary = sal;
            IDNumber = id;
        }
        //Define Method to display
        public void  DisplayInfo()//Information about object
        {
            Console.WriteLine($"|{IDNumber,-7}|{LastName,15}|{FirstName,15}|{MiddleName,15}|{Age,-5}|{Company,15}|{Salary + "$",-7}|");
        }
        //Define Method Sall
        public double SalWithVat()
        {
            /*
            x-12%=cur
            x-(x*12)/100=sall
            100x-12x=sal*100
            88x=100sal
            x=100sal/88
            */
            double x = (100.0 * Salary) / 88.0;
            return x;//with Tax deduction
        }
    }
class Program {
  public static void Main (string[] args) {
           //Testing this class
            Console.WriteLine($"|{" ID ",-7}|{"LastName",15}|{"FirstName",15}|{"MiddleName",15}|{"Age",-5}|{"Company",15}|{"Sall" + "$",-7}|");
            Employee emp=new Employee("Carvel","Smith","Oliver",22,"Digital ST",2560,1);
            emp.DisplayInfo();
            Console.WriteLine("Sallary with tax deduction:" + emp.SalWithVat());
            Console.ReadKey ();
  }
}
//This code build and run all type OS (I tested in Lunix)

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