Class Practice

mail@pastecode.io avatar
unknown
csharp
a month ago
3.1 kB
2
Indexable
Never
internal class Program
{
	private static void Main(string[] args)
	{
		Employee employee1 = new Employee();
		Employee alemkhan = new Employee(0, "Alemkhan", "Utepkaliyev");
		Employee tom = new Employee(1, "Tom", "Tomski", "Avangard 23", 7777777777);
		Employee sam = new Employee(2, "Sam", "Samski", "Nursaya 23", 7771234578, "Kazakstan", "Sam@gmail.com", true);

		Employee[] employees = new Employee[] { alemkhan, sam, tom, employee1 };

		Console.WriteLine("1. Вывести всю инфу");
		Console.WriteLine("2. Вывести короткую инфу");

		switch (Convert.ToInt32(Console.ReadLine()))
		{
			case 1:
				foreach (Employee employee in employees)
				{
					employee.PrintInfo();
				}
				break;
			case 2:
				foreach (Employee employee in employees)
				{
					employee.PrintShortInfo();
				}
				break;
			default:
				break;
		}

	}
}

class Employee
{
	// Поля
	public int Id;
	public string FirstName;
	public string LastName;
	public string Address;
	public long PhoneNumber;
	public string Location;
	public string Email;
	public bool IsActive;

	public Employee()
	{

	}

	// Конструктор 1
	/// <summary>
	/// Для создания обьекта с айди, именем и фамилией
	/// </summary>
	/// <param name="id"></param>
	/// <param name="firstName"></param>
	/// <param name="lastName"></param>
	public Employee(int id, string firstName, string lastName)
	{
		Id = id;
		FirstName = firstName;
		LastName = lastName;
	}

	// Конструктор 2
	public Employee(int id, string firstName, string lastName, string address, long phoneNumber)
	{
		Id = id;
		FirstName = firstName;
		LastName = lastName;
		Address = address;
		PhoneNumber = phoneNumber;
	}

	// Конструктор 3
	public Employee(int id, string firstName, string lastName, string address, long phoneNumber, string location, string email, bool isActive)
	{
		Id = id;
		FirstName = firstName;
		LastName = lastName;
		Address = address;
		PhoneNumber = phoneNumber;
		Location = location;
		Email = email;
		IsActive = isActive;
	}

	// Метод для вывода всей информации об обьекте
	public void PrintInfo()
	{
		Console.WriteLine("===================================");
		Console.WriteLine($"ID: {Id}");
		Console.WriteLine($"Имя: {FirstName}");
		Console.WriteLine($"Фамилия: {LastName}");
		Console.WriteLine($"Адрес: {Address}");
		Console.WriteLine($"Номер телефона: {PhoneNumber}");
		Console.WriteLine($"Местоположение: {Location}");
		Console.WriteLine($"Эл. почта: {Email}");
		Console.WriteLine($"Статус: {IsActive}");
		Console.WriteLine("===================================");
	}

	public void PrintShortInfo()
	{
		Console.WriteLine("===================================");
		Console.WriteLine($"ID: {Id}");
		Console.WriteLine($"Имя: {FirstName}");
		Console.WriteLine($"Фамилия: {LastName}");
		Console.WriteLine("===================================");
	}
}
Leave a Comment