theme changed
This commit is contained in:
27
labs/lab9/LearningCenter/Person.cs
Normal file
27
labs/lab9/LearningCenter/Person.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
|
||||
abstract class Person
|
||||
{
|
||||
public string LastName { get; }
|
||||
public DateTime BirthDate { get; }
|
||||
|
||||
protected Person(string lastName, DateTime birthDate)
|
||||
{
|
||||
LastName = lastName;
|
||||
BirthDate = birthDate;
|
||||
}
|
||||
|
||||
public int Age()
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
int a = today.Year - BirthDate.Year;
|
||||
if (BirthDate.Date > today.AddYears(-a)) a--;
|
||||
return a;
|
||||
}
|
||||
|
||||
public virtual void Show()
|
||||
{
|
||||
Console.WriteLine("{0}, возраст: {1}", LastName, Age());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user