In: Computer Science
Using C#:
Write a class named Employee that has the following properties:
The class should have the following overloaded constructors:
In an application, create three Employee objects to hold the following data:
Name IdNumber Department Position
Susan Myers 47899 Accounting Vice President
Mark Jones 39119 IT Programmer
Joy Rogers 81774 Manufacturing Engineer
The application should store this data in the three objects and display the data for each employee on the screen.
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Employee_Class
{
class Employee
{
private string Name, Department, Position;
private int IdNumber;
public Employee(string name, int id, string dept, string pos)
{
Name = name;
Department = dept;
IdNumber = id;
Position = pos;
}
public Employee(string name, int id)
{
Name = name;
Department = "";
IdNumber = id;
Position = "";
}
public Employee()
{
Name = "";
Department = "";
IdNumber = 0;
Position = "";
}
public override string ToString()
{
String data = String.Format("{0,-20} {1,-15} {2,-25} {3,
-10}",Name,IdNumber,Department,Position);
return data;
}
}
class Program
{
static void Main(string[] args)
{
String output = String.Format("{0,-20} {1,-15} {2,-25} {3, -10} ",
"Name", "IdNumber", "Department", "Position");
Employee e1 = new Employee("Susan Myers", 47899, "Accounting",
"Vice President");
Employee e2 = new Employee("Mark Jones ", 39119, "IT",
"Programmer");
Employee e3 = new Employee("Joy Rogers", 81774, "Manufacturing ",
"Engineer");
Console.WriteLine(output);
Console.WriteLine(e1);
Console.WriteLine(e2);
Console.WriteLine(e3);
}
}
}
output
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.