Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Artem Nikolaev (Rabbit) #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions CourseApp/Artem Nikolaev (Rabbit)
Original file line number Diff line number Diff line change
@@ -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++;
}
}
}