Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace dog
- {
- class Dog
- {
- private int _age;
- private string _name;
- private string _owner;
- private Random rnd = new Random();
- public string color;
- public string eyecolor;
- public Dog(int age, string name, string owner)
- {
- _age = age;
- _name = name;
- _owner = owner;
- }
- public Dog() : this(1, "Barsik",
- "Oleg")
- { }
- public int Age
- {
- get
- {
- return _age;
- }
- }
- public string Name
- {
- get
- {
- return _name;
- }
- }
- public string Owner
- {
- get { return _owner; }
- }
- public void IncreaseAge()
- {
- _age++;
- }
- public void IncreaseAge(int step)
- {
- _age += step;
- if (step < 0)
- throw new ArgumentException();
- }
- public void RandomAge()
- {
- _age = rnd.Next(3, 16);
- }
- public void RandomName()
- {
- string[] names = { "Bobby", "Boss", "Tommy", "Bober" };
- _name = names[rnd.Next(0, 4)];
- }
- public void RandomColor()
- {
- string[] colors = { "white", "black", "brown" };
- color = colors[rnd.Next(0, 3)];
- }
- public void RandomEyeColor()
- {
- string[] eyecolors = { "blue", "green", "yellow", "gray" };
- eyecolor = eyecolors[rnd.Next(0, 4)];
- }
- public override string ToString()
- {
- return $"Cat called {_name}, age = {_age}, owner = {_owner}, color = {color}, eyecolor = {eyecolor}";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- try
- {
- int n;
- Dog dog = new Dog();
- do
- {
- Console.WriteLine("Введите количество собак n: ");
- }
- while (!int.TryParse(Console.ReadLine(), out n) || n < 1);
- Console.WriteLine();
- string[] mas = new string[n];
- for (int i = 0; i < n; i++)
- {
- dog.RandomAge();
- dog.RandomName();
- dog.RandomColor();
- dog.RandomEyeColor();
- mas[i] = dog.ToString(); ;
- Console.WriteLine(mas[i]);
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement