using System;
enum Rank { First, Second, High }
class License
{
public string Organization { get; set; }
public string Qualification { get; set; }
public DateTime IssueDate { get; set; }
public License(string org, string qual, DateTime date)
{
Organization = org;
Qualification = qual;
IssueDate = date;
}
public License() : this("Default Org", "Default Qual", DateTime.Now) { }
public override string ToString() =>
$"Org: {Organization}, Qual: {Qualification}, Date: {IssueDate:yyyy-MM-dd}";
}
class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Person(string first, string last)
{
FirstName = first;
LastName = last;
}
public Person() : this("John", "Doe") { }
public override string ToString() => $"{FirstName} {LastName}";
}
class StationWorker
{
public Person Person { get; set; }
public string Specialization { get; set; }
public Rank Rank { get; set; }
public int Experience { get; set; }
public License[] Licenses { get; set; }
public License FirstLicense
{
get
{
if (Licenses == null || Licenses.Length == 0) return null;
License first = Licenses[0];
foreach (var license in Licenses)
if (license.IssueDate < first.IssueDate)
first = license;
return first;
}
}
public StationWorker
(Person person
, string spec
, Rank rank
, int exp) {
Person = person;
Specialization = spec;
Rank = rank;
Licenses = Array.Empty<License>();
}
public StationWorker() : this(new Person(), "Mechanic", Rank.First, 0) { }
public void AddLicense(params License[] newLicenses)
{
if (Licenses == null)
{
Licenses = newLicenses;
return;
}
var combined = new License[Licenses.Length + newLicenses.Length];
Array.Copy(Licenses, combined, Licenses.Length);
Array.Copy(newLicenses, 0, combined, Licenses.Length, newLicenses.Length);
Licenses = combined;
}
public override string ToString()
{
string result = $"Person: {Person}, Spec: {Specialization}, " +
$"Rank: {Rank}, Exp: {Experience} years\nLicenses:\n";
if (Licenses.Length > 0)
foreach (var license in Licenses)
result += $" {license}\n";
else
result += " No licenses\n";
return result;
}
public virtual string ToShortString() =>
$"Person: {Person}, Spec: {Specialization}, Rank: {Rank}, Exp: {Experience} years";
}
class Program
{
static void Main()
{
// 1
var worker1 = new StationWorker();
Console.WriteLine("1. Конструктор без параметрів:");
Console.WriteLine(worker1.ToString());
// 2
worker1.Person = new Person("Ivan", "Petrenko");
worker1.Specialization = "Engine Specialist";
worker1.Rank = Rank.High;
worker1.Experience = 5;
Console.WriteLine("\n2. Після зміни властивостей:");
Console.WriteLine(worker1.ToShortString());
// 3
var worker2 = new StationWorker(
new Person("Maria", "Ivanova"),
"Electric Systems",
Rank.Second,
3
);
Console.WriteLine("\n3. Конструктор з параметрами:");
Console.WriteLine(worker2.ToString());
// 4
worker2.AddLicense(
new License("AutoTech", "Engine Repair", new DateTime(2020, 5, 15)),
new License("EVA", "EV Specialist", new DateTime(2022, 3, 10))
);
Console.WriteLine("4. Після додавання ліцензій:");
Console.WriteLine(worker2.ToString());
// 5
Console.WriteLine("5. Перша ліцензія:");
Console.WriteLine(worker2.FirstLicense?.ToString() ?? "Ліцензії відсутні");
}
}