-
Notifications
You must be signed in to change notification settings - Fork 5
/
Homework4_Person
74 lines (72 loc) · 2.02 KB
/
Homework4_Person
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Homework4
{
class Person
{
private string name;
private DateTime birthYear;
public string Name
{
get { return name; }
set { name = value; }
}
public DateTime BirthDay
{ get{ return birthYear; } }
public Person()
{ }
public Person(string name, DateTime birthYear)
{
this.name = name;
this.birthYear = birthYear;
}
public int Age()
{
DateTime date = DateTime.Now;
return date.Year - birthYear.Year;
}
public static Person Input()
{
Console.Write("Enter person name: ");
string name = Console.ReadLine();
Console.Write("Enter person birthday: ");
DateTime birthYear = new DateTime();
try
{
birthYear = DateTime.Parse(Console.ReadLine());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine("Correct format is: 2020,01,01");
}
return new Person(name, birthYear);
}
public string ChangeName(string newName)
{
return name = newName;
}
public override string ToString()
{
return string.Format($"Name is {name} - birthday is {birthYear}");
}
public static void Output(Person[] person)
{
for (int i = 0; i < person.Length; i++)
{
Console.WriteLine(person[i].ToString());
}
}
public static bool operator ==(Person person1, Person person2)
{
return person1.name == person2.name;
}
public static bool operator !=(Person person1, Person person2)
{
return person1.name != person2.name;
}
}
}