Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. /*
  2. * Created by SharpDevelop.
  3. * User: User
  4. * Date: 27.09.2016
  5. * Time: 23:23
  6. *
  7. * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8. */
  9. using System;
  10.  
  11. namespace USER
  12. {
  13. /// <summary>
  14. /// Description of user.
  15. /// </summary>
  16. public class user
  17. {
  18. string name;
  19. string surname;
  20. string middle_name;
  21. DateTime date_of_birth;
  22.  
  23. static string check_name(string check_str)
  24. {
  25. if (String.IsNullOrEmpty(check_str))
  26. {
  27. throw new ArgumentException("Имя и фамилия не может быть null или пустой строкой");
  28. }
  29. char[] arname = check_str.ToCharArray();
  30. for (int i = 1; i < arname.Length; i++)
  31. {
  32. arname[i] = char.ToLower(arname[i]);
  33. }
  34. arname[0] = char.ToUpper(arname[0]);
  35. return new string(arname);
  36. }
  37.  
  38. static string check_middle_name(string check_str)
  39. {
  40. if (String.Empty == check_str)
  41. {
  42. throw new ArgumentException("Очество не может быть пустой строкой");
  43. }
  44. if (check_str == null)
  45. {
  46. return null;
  47. }
  48. char[] arname = check_str.ToCharArray();
  49. for (int i = 1; i < arname.Length; i++)
  50. {
  51. arname[i] = char.ToLower(arname[i]);
  52. }
  53. arname[0] = char.ToUpper(arname[0]);
  54. return new string(arname);
  55. }
  56.  
  57. static DateTime check_data(DateTime date)
  58. {
  59. if (date > DateTime.Now)
  60. {
  61. throw new ArgumentException("Дата не может быть в будущем");
  62. }
  63. if (GetYear(date) > 150)
  64. {
  65. throw new ArgumentException("Дата такова, что возраст человека больше 150 лет");
  66. }
  67. return date;
  68. }
  69.  
  70. public string Name
  71. {
  72. get
  73. {
  74. return name;
  75. }
  76. set
  77. {
  78. name = check_name(value);
  79. }
  80. }
  81.  
  82. public string Middle_name
  83. {
  84. get
  85. {
  86. if (middle_name == null)
  87. {
  88. return "";
  89. }
  90. return middle_name;
  91. }
  92. set
  93. {
  94. middle_name = check_middle_name(value);
  95. }
  96. }
  97.  
  98. public string Surname
  99. {
  100. get
  101. {
  102. return surname;
  103. }
  104. set
  105. {
  106. surname = check_name(value);
  107. }
  108. }
  109.  
  110. public DateTime Date_of_birth
  111. {
  112. get
  113. {
  114. return date_of_birth;
  115. }
  116. set
  117. {
  118. date_of_birth = check_data(value);
  119. }
  120. }
  121.  
  122. public int Age
  123. {
  124. get
  125. {
  126. return GetYear(date_of_birth);
  127. }
  128. }
  129.  
  130. protected static int GetYear(DateTime date_of_birth)
  131. {
  132. int age;
  133. age = DateTime.Now.Year - date_of_birth.Year;
  134. if (DateTime.Now.Month < date_of_birth.Month ||
  135. (DateTime.Now.Month == date_of_birth.Month && DateTime.Now.Day < date_of_birth.Day)) age--;
  136. return age;
  137. }
  138.  
  139. public user(string name, string surname, string middle_name, DateTime date_of_birth)
  140. {
  141. Name = name;
  142. Surname = surname;
  143. Middle_name = middle_name;
  144. Date_of_birth = date_of_birth;
  145. }
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement