Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: User
- * Date: 27.09.2016
- * Time: 23:23
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- namespace USER
- {
- /// <summary>
- /// Description of user.
- /// </summary>
- public class user
- {
- string name;
- string surname;
- string middle_name;
- DateTime date_of_birth;
- static string check_name(string check_str)
- {
- if (String.IsNullOrEmpty(check_str))
- {
- throw new ArgumentException("Имя и фамилия не может быть null или пустой строкой");
- }
- char[] arname = check_str.ToCharArray();
- for (int i = 1; i < arname.Length; i++)
- {
- arname[i] = char.ToLower(arname[i]);
- }
- arname[0] = char.ToUpper(arname[0]);
- return new string(arname);
- }
- static string check_middle_name(string check_str)
- {
- if (String.Empty == check_str)
- {
- throw new ArgumentException("Очество не может быть пустой строкой");
- }
- if (check_str == null)
- {
- return null;
- }
- char[] arname = check_str.ToCharArray();
- for (int i = 1; i < arname.Length; i++)
- {
- arname[i] = char.ToLower(arname[i]);
- }
- arname[0] = char.ToUpper(arname[0]);
- return new string(arname);
- }
- static DateTime check_data(DateTime date)
- {
- if (date > DateTime.Now)
- {
- throw new ArgumentException("Дата не может быть в будущем");
- }
- if (GetYear(date) > 150)
- {
- throw new ArgumentException("Дата такова, что возраст человека больше 150 лет");
- }
- return date;
- }
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = check_name(value);
- }
- }
- public string Middle_name
- {
- get
- {
- if (middle_name == null)
- {
- return "";
- }
- return middle_name;
- }
- set
- {
- middle_name = check_middle_name(value);
- }
- }
- public string Surname
- {
- get
- {
- return surname;
- }
- set
- {
- surname = check_name(value);
- }
- }
- public DateTime Date_of_birth
- {
- get
- {
- return date_of_birth;
- }
- set
- {
- date_of_birth = check_data(value);
- }
- }
- public int Age
- {
- get
- {
- return GetYear(date_of_birth);
- }
- }
- protected static int GetYear(DateTime date_of_birth)
- {
- int age;
- age = DateTime.Now.Year - date_of_birth.Year;
- if (DateTime.Now.Month < date_of_birth.Month ||
- (DateTime.Now.Month == date_of_birth.Month && DateTime.Now.Day < date_of_birth.Day)) age--;
- return age;
- }
- public user(string name, string surname, string middle_name, DateTime date_of_birth)
- {
- Name = name;
- Surname = surname;
- Middle_name = middle_name;
- Date_of_birth = date_of_birth;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement