124 lines
3.5 KiB
C#
Executable File
124 lines
3.5 KiB
C#
Executable File
using System.ComponentModel.DataAnnotations;
|
|
using System.Runtime.CompilerServices;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
enum _Type_Animal{
|
|
herbivorous, // травоядный
|
|
predator, // хищник
|
|
omnivorous, // всеядный
|
|
insectivorous // насекомоядный
|
|
}
|
|
|
|
enum _Habitat{
|
|
water_env, // водная среда
|
|
earth_env, // наземная среда
|
|
wind_env // воздушная среда
|
|
}
|
|
|
|
enum _Continent{
|
|
africa,
|
|
north_am,
|
|
south_am,
|
|
australia,
|
|
antarctica,
|
|
eurasia
|
|
}
|
|
|
|
class Animal{
|
|
|
|
//-constructors-----------------------------------
|
|
public Animal(){
|
|
Console.WriteLine("базовый конструктор");
|
|
}
|
|
|
|
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{ set; }
|
|
private _Habitat Habitat{ set; }
|
|
private _Continent Continent{ set; }
|
|
} |