Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Task2
- {
- public class Employee : User, IEquatable<Employee>
- {
- private string _title;
- private DateTime _hireDate;
- public int Experience
- {
- get
- {
- TimeSpan timeSpan = DateTime.Now - _hireDate;
- return (int)(timeSpan.TotalDays / 364.75);
- }
- }
- public string Title
- {
- get => _title;
- set
- {
- if (value == null)
- throw new ArgumentNullException("Должность не может быть null");
- if (value.Length < 1)
- throw new ArgumentException("Должность не может быть пустой!");
- _title = new string(value);
- }
- }
- public Employee(DateTime dateOfBirth, string name, string lastName, string patronymic, string title, DateTime hireDate)
- : base(dateOfBirth, name, lastName, patronymic)
- {
- if (hireDate > DateTime.Now)
- throw new ArgumentException("Данный пользователь ещё не мог быть нанят!");
- Title = title;
- _hireDate = hireDate;
- }
- public override string ToString() =>
- base.ToString() +
- "должность: " + Title + "\n" +
- "опыт: " + Experience + " года\n" +
- "нанят:" + _hireDate + "\n";
- public bool Equals(Employee other)
- {
- if (other is null)
- return false;
- if (ReferenceEquals(this, other))
- return true;
- if (this.GetType() != other.GetType())
- return false;
- return (base.Equals(other) && this.Experience == other.Experience
- && this.Title == other.Title);
- }
- public override bool Equals(object obj)
- {
- if (obj is null)
- return false;
- if (ReferenceEquals(this, obj))
- return true;
- if (this.GetType() != obj.GetType())
- return false;
- return this.Equals(obj as Employee);
- }
- public override int GetHashCode()
- {
- return HashCode.Combine(base.GetHashCode(), Experience, Title);
- }
- public static bool operator ==(Employee employee1, Employee employee2)
- {
- if (employee1 is null || employee2 is null)
- return false;
- return employee1.Equals(employee2);
- }
- public static bool operator !=(Employee employee1, Employee employee2)
- {
- return !(employee1 == employee2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement