127 lines
3.6 KiB
C#
Executable File
127 lines
3.6 KiB
C#
Executable File
using System.ComponentModel.DataAnnotations;
|
|
using System.Runtime.CompilerServices;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
public enum _Type_Animal{
|
|
herbivorous, // травоядный
|
|
predator, // хищник
|
|
omnivorous, // всеядный
|
|
insectivorous // насекомоядный
|
|
}
|
|
|
|
public enum _Habitat{
|
|
water_env, // водная среда
|
|
earth_env, // наземная среда
|
|
wind_env // воздушная среда
|
|
}
|
|
|
|
public enum _Continent{
|
|
africa,
|
|
north_am,
|
|
south_am,
|
|
australia,
|
|
antarctica,
|
|
eurasia
|
|
}
|
|
|
|
class Animal{
|
|
|
|
//-constructors-----------------------------------
|
|
public Animal(){
|
|
Console.WriteLine(">>базовый конструктор");
|
|
_name = "пусто";
|
|
_age = 0;
|
|
_count_limbs = 0;
|
|
}
|
|
|
|
public Animal(string _name_, int _age_, int _count_limbs_,
|
|
_Type_Animal _type_animal_, _Habitat _habitat_,
|
|
_Continent _continent_){
|
|
|
|
Console.WriteLine(">>конструктор с параметрами");
|
|
_name = _name_;
|
|
_age = _age_;
|
|
_count_limbs = _count_limbs_;
|
|
|
|
type_animal = _type_animal_;
|
|
habitat = _habitat_;
|
|
continent = _continent_;
|
|
}
|
|
|
|
//-override-operators-----------------------------
|
|
public static bool operator ==(Animal? animal_1, Animal? animal_2){
|
|
return ReferenceEquals(animal_1, animal_2);
|
|
}
|
|
|
|
public static bool operator !=(Animal? animal_1, Animal? animal_2){
|
|
return !(animal_1 == animal_2);
|
|
}
|
|
|
|
//-methods----------------------------------------
|
|
public void GetSound(){
|
|
Console.WriteLine(" >издает звук!");
|
|
}
|
|
|
|
public void CanSwim(){
|
|
if (habitat == _Habitat.water_env){
|
|
Console.WriteLine(" >животное умеет плавать!");
|
|
}
|
|
else{
|
|
Console.WriteLine(" >животное не умеет плавать!");
|
|
}
|
|
}
|
|
|
|
public void CanFly(){
|
|
if (habitat == _Habitat.wind_env){
|
|
Console.WriteLine(" >животное умеет летать!");
|
|
}
|
|
else{
|
|
Console.WriteLine(" >животное не умеет летать!");
|
|
}
|
|
}
|
|
|
|
public void ExistsTail(){
|
|
if (type_animal == _Type_Animal.insectivorous){
|
|
Console.WriteLine(" >у животного нет хвоста!");
|
|
}
|
|
else{
|
|
Console.WriteLine(" >у животного есть хвост!");
|
|
}
|
|
}
|
|
|
|
public void GetAllData(){
|
|
Console.WriteLine("имя: " + _name);
|
|
Console.WriteLine("возраст: " + _age);
|
|
Console.WriteLine("количество конечностей: " + _count_limbs);
|
|
Console.WriteLine("тип животного: " + type_animal);
|
|
Console.WriteLine("среда обитания: " + habitat);
|
|
Console.WriteLine("континент: " + continent);
|
|
}
|
|
|
|
//-public-fields----------------------------------
|
|
public string Name{
|
|
get{
|
|
return _name;
|
|
}
|
|
}
|
|
|
|
public int Age{
|
|
get{
|
|
return _age;
|
|
}
|
|
}
|
|
|
|
public int Count_Limbs{
|
|
get{
|
|
return _count_limbs;
|
|
}
|
|
}
|
|
|
|
//-private-fields---------------------------------
|
|
private string _name;
|
|
private int _age;
|
|
private int _count_limbs;
|
|
private _Type_Animal type_animal;
|
|
private _Habitat habitat;
|
|
private _Continent continent;
|
|
} |