Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ClassesWork
  4. {
  5.  
  6. class Dog
  7. {
  8. protected int age;
  9. protected string host;
  10. protected string name;
  11.  
  12. public int Age
  13. {
  14. get
  15. {
  16. return age;
  17. }
  18. }
  19. public string Host
  20. {
  21. get
  22. {
  23. return name;
  24. }
  25. }
  26.  
  27. public string Name
  28. {
  29. get
  30. {
  31. return name;
  32. }
  33. }
  34.  
  35.  
  36. private string furColor;
  37. public string FurColor
  38. {
  39. get { return furColor; }
  40. set { furColor = value; }
  41. }
  42.  
  43. private string eyeColor;
  44.  
  45. public string EyeColor
  46. {
  47. get { return eyeColor; }
  48. set { eyeColor = value; }
  49. }
  50.  
  51.  
  52. public void IncreaseAge()
  53. {
  54. age++;
  55. }
  56. public void IncreaseAge(int inputAge)
  57. {
  58. if (inputAge > 0)
  59. age += inputAge;
  60. }
  61.  
  62. public Dog(int age, string host, string name)
  63. {
  64. this.age = age;
  65. this.host = host;
  66. this.name = name;
  67. }
  68. public override string ToString()
  69. {
  70. return $"Хозяин: {host}, Имя: {name}, Возраст: {age}, Шерсть: {furColor}, Глаза: {eyeColor}";
  71. }
  72. }
  73. class Program
  74. {
  75. static string[] names = { "Jack", "Tim", "Owo" };
  76. static string[] furColors = { "Black", "White", "Brown" };
  77. static string[] eyeColors = { "Brown", "Blue", "Green" };
  78. static Random random = new Random();
  79. static void Main()
  80. {
  81. uint n;
  82. Console.WriteLine("Введите число: ");
  83. ReadData(out n);
  84.  
  85. Dog[] dogs = new Dog[n];
  86. for (int i = 0; i < n; i++)
  87. {
  88. dogs[i] = new Dog(random.Next(3,16),"Marina sex mashina", names[random.Next(3)]);
  89. dogs[i].FurColor = furColors[random.Next(3)];
  90. dogs[i].EyeColor = eyeColors[random.Next(3)];
  91. Console.WriteLine(dogs[i]);
  92. }
  93. Console.ReadLine();
  94. }
  95.  
  96. static bool Check(out uint input)
  97. {
  98. return uint.TryParse(Console.ReadLine(), out input);
  99. }
  100. static void ReadData(out uint input)
  101. {
  102. if (!Check(out input))
  103. {
  104. Console.WriteLine("Введенные данные неверны. Повторите ввод.");
  105. ReadData(out input);
  106. }
  107. }
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement