Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
class Date
{
public int Day_increase(int n)
{
return day + n;
}
int year;
int day;
int month;
public Date()
{
year = 2020;
day = 25;
month = 5;
}
public Date(int y, int m, int d)
{
year = y;
month = m;
day = d;
}
public int Property_Year
{
get
{
return year;
}
set
{
if (value > -1)
year = value;
}
}
public int Property_Month
{
get
{
return month;
}
set
{
if (value > 0 && value < 13)
month = value;
}
}
public int Property_Day
{
get
{
return day;
}
set
{
if (year % 4 == 0 || year % 100 == 0 || year % 400 == 0)
{
if (month == 2 && value <= 28)
day = value;
else if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && value <= 31)
day = value;
else if ((month == 4 || month == 6 || month == 9 || month == 8 || month == 11) && value < 30)
day = value;
else
Console.WriteLine("Не существует");
}
else
{
if (month == 2 && value <= 29)
day = value;
else if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && value <= 31)
day = value;
else if ((month == 4 || month == 6 || month == 9 || month == 8 || month == 11) && value < 30)
day = value;
else
Console.WriteLine("Не существует");
}
}
}
public void Print(int n)
{
switch (n)
{
case 1:
{
Console.WriteLine("Год: " + year);
Console.ReadKey();
Console.Clear();
}
break;
case 2:
{
Console.WriteLine("Месяц: " + month);
Console.ReadKey();
Console.Clear();
}
break;
case 3:
{
Console.WriteLine("День: " + day);
Console.ReadKey();
Console.Clear();
}
break;
}
}
class Program
{
static void Main(string[] args)
{
bool f = true;
Date date = new Date();
do
{
Console.WriteLine("Команды:\n1)Узнать год\n" +
"2)Узнать месяц\n" +
"3)Узнать день\n" +
"4)Установка даты\n" +
"5)Выход\n");
string g = Console.ReadLine();
switch (g)
{
case "1":
{
date.Print(1);
}
break;
case "2":
{
date.Print(2);
}
break;
case "3":
{
date.Print(3);
}
break;
case "4":
{
Console.WriteLine("Введите год:");
date.Property_Year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите месяц:");
date.Property_Month = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите день:");
date.Property_Day = Convert.ToInt32(Console.ReadLine());
Console.ReadKey();
Console.Clear();
}
break;
case "5":
{
f = false;
Console.WriteLine("Thanks yoy <3");
}
break;
}
}
while (f == true);
}
}
}
}