Guest User

Untitled

a guest
Nov 19th, 2019
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace dog
  8. {
  9. class Dog
  10. {
  11. private int _age;
  12. private string _name;
  13. private string _owner;
  14. private Random rnd = new Random();
  15.  
  16. public string color;
  17. public string eyecolor;
  18. public Dog(int age, string name, string owner)
  19. {
  20. _age = age;
  21. _name = name;
  22. _owner = owner;
  23. }
  24.  
  25. public Dog() : this(1, "Barsik",
  26. "Oleg")
  27. { }
  28. public int Age
  29. {
  30. get
  31. {
  32. return _age;
  33. }
  34. }
  35.  
  36. public string Name
  37. {
  38. get
  39. {
  40. return _name;
  41. }
  42. }
  43.  
  44. public string Owner
  45. {
  46. get { return _owner; }
  47. }
  48.  
  49. public void IncreaseAge()
  50. {
  51. _age++;
  52. }
  53.  
  54. public void IncreaseAge(int step)
  55. {
  56. _age += step;
  57. if (step < 0)
  58. throw new ArgumentException();
  59. }
  60. public void RandomAge()
  61. {
  62. _age = rnd.Next(3, 16);
  63. }
  64. public void RandomName()
  65. {
  66.  
  67. string[] names = { "Bobby", "Boss", "Tommy", "Bober" };
  68. _name = names[rnd.Next(0, 4)];
  69. }
  70. public void RandomColor()
  71. {
  72. string[] colors = { "white", "black", "brown" };
  73. color = colors[rnd.Next(0, 3)];
  74. }
  75. public void RandomEyeColor()
  76. {
  77. string[] eyecolors = { "blue", "green", "yellow", "gray" };
  78. eyecolor = eyecolors[rnd.Next(0, 4)];
  79. }
  80. public override string ToString()
  81. {
  82. return $"Cat called {_name}, age = {_age}, owner = {_owner}, color = {color}, eyecolor = {eyecolor}";
  83. }
  84.  
  85. }
  86. class Program
  87. {
  88. static void Main(string[] args)
  89. {
  90. try
  91. {
  92. int n;
  93. Dog dog = new Dog();
  94. do
  95. {
  96. Console.WriteLine("Введите количество собак n: ");
  97. }
  98. while (!int.TryParse(Console.ReadLine(), out n) || n < 1);
  99. Console.WriteLine();
  100. string[] mas = new string[n];
  101. for (int i = 0; i < n; i++)
  102. {
  103.  
  104. dog.RandomAge();
  105. dog.RandomName();
  106. dog.RandomColor();
  107. dog.RandomEyeColor();
  108. mas[i] = dog.ToString(); ;
  109. Console.WriteLine(mas[i]);
  110. Console.WriteLine();
  111. }
  112. Console.ReadLine();
  113.  
  114. }
  115. catch (Exception ex)
  116. {
  117. Console.WriteLine(ex.Message);
  118. }
  119. }
  120.  
  121. }
  122. }
RAW Paste Data