From 5af5691b3e6522a5488e2fe41513d313722cd82a Mon Sep 17 00:00:00 2001 From: Artem199837 <55375205+Artem199837@users.noreply.github.com> Date: Mon, 6 Jan 2020 14:20:39 +0300 Subject: [PATCH] Create Artem Nikolaev (Rabbit) --- CourseApp/Artem Nikolaev (Rabbit) | 86 +++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 CourseApp/Artem Nikolaev (Rabbit) diff --git a/CourseApp/Artem Nikolaev (Rabbit) b/CourseApp/Artem Nikolaev (Rabbit) new file mode 100644 index 0000000..4a56211 --- /dev/null +++ b/CourseApp/Artem Nikolaev (Rabbit) @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CourseApp +{ + public class Rabbit + { + private int carrot; + private int age; + + public Rabbit() + : this("Неизвестно") + { + } + + public Rabbit(string name) + : this(name, 0) + { + } + + public Rabbit(string name, int age) + : this(name, age, 0) + { + } + + public Rabbit(string name, int age, int carrot) + { + Name = name; + Age = age; + Carrot = carrot; + } + + public int Age + { + get + { + return this.age; + } + + set + { + if (value >= 0 && value <= 2) + { + this.age = value; + } + else + { + throw new System.Exception(); + } + } + } + + public string Name { get; set; } + + public int Carrot + { + get + { + return this.carrot; + } + + set + { + if (value >= 0) + { + this.carrot = value; + } + else + { + throw new System.Exception(); + } + } + } + + public override string ToString() + { + return $"Имя:{Name}, Возраст:{Age}, Запасы моркови:{carrot}"; + } + + public void FoundСarrot() + { + this.Carrot++; + } + } +}