Files
study_oop1/Animal.cs
T

127 lines
3.6 KiB
C#
Raw Normal View History

2026-09-12 15:19:13 +06:00
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;
using static System.Net.Mime.MediaTypeNames;
2026-09-12 17:44:11 +06:00
public enum _Type_Animal{
2026-09-12 15:19:13 +06:00
herbivorous, // травоядный
predator, // хищник
omnivorous, // всеядный
insectivorous // насекомоядный
}
2026-09-12 17:44:11 +06:00
public enum _Habitat{
2026-09-12 15:19:13 +06:00
water_env, // водная среда
earth_env, // наземная среда
wind_env // воздушная среда
}
2026-09-12 17:44:11 +06:00
public enum _Continent{
2026-09-12 15:19:13 +06:00
africa,
north_am,
south_am,
australia,
antarctica,
eurasia
}
class Animal{
//-constructors-----------------------------------
public Animal(){
2026-09-12 17:44:11 +06:00
Console.WriteLine(">>базовый конструктор");
_name = "пусто";
_age = 0;
_count_limbs = 0;
2026-09-12 15:19:13 +06:00
}
public Animal(string _name_, int _age_, int _count_limbs_,
2026-09-12 17:44:11 +06:00
_Type_Animal _type_animal_, _Habitat _habitat_,
_Continent _continent_){
2026-09-12 15:19:13 +06:00
2026-09-12 17:44:11 +06:00
Console.WriteLine(">>конструктор с параметрами");
2026-09-12 15:19:13 +06:00
_name = _name_;
_age = _age_;
_count_limbs = _count_limbs_;
2026-09-12 17:44:11 +06:00
type_animal = _type_animal_;
habitat = _habitat_;
continent = _continent_;
2026-09-12 15:19:13 +06:00
}
//-override-operators-----------------------------
2026-09-12 17:44:11 +06:00
public static bool operator ==(Animal? animal_1, Animal? animal_2){
2026-09-12 15:19:13 +06:00
return ReferenceEquals(animal_1, animal_2);
}
2026-09-12 17:44:11 +06:00
public static bool operator !=(Animal? animal_1, Animal? animal_2){
2026-09-12 15:19:13 +06:00
return !(animal_1 == animal_2);
}
//-methods----------------------------------------
public void GetSound(){
2026-09-12 17:44:11 +06:00
Console.WriteLine(" >издает звук!");
2026-09-12 15:19:13 +06:00
}
public void CanSwim(){
2026-09-12 17:44:11 +06:00
if (habitat == _Habitat.water_env){
Console.WriteLine(" >животное умеет плавать!");
2026-09-12 15:19:13 +06:00
}
else{
2026-09-12 17:44:11 +06:00
Console.WriteLine(" >животное не умеет плавать!");
2026-09-12 15:19:13 +06:00
}
}
public void CanFly(){
2026-09-12 17:44:11 +06:00
if (habitat == _Habitat.wind_env){
Console.WriteLine(" >животное умеет летать!");
2026-09-12 15:19:13 +06:00
}
else{
2026-09-12 17:44:11 +06:00
Console.WriteLine(" >животное не умеет летать!");
2026-09-12 15:19:13 +06:00
}
}
public void ExistsTail(){
2026-09-12 17:44:11 +06:00
if (type_animal == _Type_Animal.insectivorous){
Console.WriteLine(" >у животного нет хвоста!");
2026-09-12 15:19:13 +06:00
}
else{
2026-09-12 17:44:11 +06:00
Console.WriteLine(" >у животного есть хвост!");
2026-09-12 15:19:13 +06:00
}
}
public void GetAllData(){
2026-09-12 17:44:11 +06:00
Console.WriteLine("имя: " + _name);
Console.WriteLine("возраст: " + _age);
Console.WriteLine("количество конечностей: " + _count_limbs);
Console.WriteLine("тип животного: " + type_animal);
Console.WriteLine("среда обитания: " + habitat);
Console.WriteLine("континент: " + continent);
2026-09-12 15:19:13 +06:00
}
//-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;
2026-09-12 17:44:11 +06:00
private _Type_Animal type_animal;
private _Habitat habitat;
private _Continent continent;
2026-09-12 15:19:13 +06:00
}