Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace miispi_praktika_2/* 13.республика монархия государство, конструкторы
- методы ввода вывода описание методов индивидуального задания*/
- {
- class Government
- {
- private string name;
- private bool parlament;
- private int legimacy;
- public Government() { name = ""; parlament = false; legimacy = 0; }// конструктор по умолчанию
- public Government(string _name, bool _parlament, int _legimacy)// конструктор с параметрами
- {
- name = _name;
- parlament = _parlament;
- legimacy = _legimacy;
- }
- public string Name
- {
- set
- {
- name = value;
- }
- get
- {
- return name;
- }
- }
- public bool Parlament
- {
- set
- {
- parlament = value;
- }
- get
- {
- return parlament;
- }
- }
- public int Legimacy
- {
- set
- {
- if (value < 0 || value > 100)
- {
- Console.WriteLine("Легитимность должна быть в периоде от 0 до 100");
- }
- else
- {
- legimacy = value;
- }
- }
- get { return legimacy; }
- }
- public void Print()
- {
- Console.WriteLine($"Название страны: {name}. Присутствует ли парламент: {parlament}. На сколько процентов легитимна власть: {legimacy}.\n");
- }
- public override string ToString()//перегрузка метода класса obj ToString
- {
- return string.Format("Name: {0}, Parlament: {1}, Legimacy: {2}", name, parlament, legimacy);
- }
- }
- class Monarchy : Government
- {
- private string dinasty;
- private bool religion;
- public Monarchy() { dinasty = ""; religion = false; }// конструктор по умолчанию
- public Monarchy(string _dinasty, bool _religion)// конструктор с параметрами
- {
- dinasty = _dinasty;
- religion = _religion;
- }
- public string Dinasty
- {
- set
- {
- dinasty = value;
- }
- get { return dinasty; }
- }
- public bool Religion
- {
- set
- {
- religion = value;
- }
- get { return religion; }
- }
- }
- class Republic : Government
- {
- private bool election;
- private string ruler;
- public Republic() { ruler = ""; election = false; }// конструктор по умолчанию
- public Republic(bool _election, string _ruler)// конструктор с параметрами
- {
- election = _election;
- ruler = _ruler;
- }
- public bool Election
- {
- set
- {
- election = value;
- }
- get
- {
- return election;
- }
- }
- public string Ruler
- {
- set
- {
- ruler = value;
- }
- get { return ruler; }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Republic usa = new Republic(true, "biden");
- Republic russia = new Republic(false, "putin");
- Monarchy uar = new Monarchy("ruricovichi", true);
- Monarchy uk = new Monarchy("lankasters", false);
- List<Government> country = new List<Government>();
- country.Add(usa);
- country.Add(russia);
- country.Add(uar);
- country.Add(uk);
- List<Government> governments = FindByDynasty(country, "lankasters");
- foreach( Government ge in governments )
- {
- Console.WriteLine(ge);
- }
- }
- static List<Government> FindByDynasty(List<Government> array, string _dinasty)
- {
- Government ge = null;
- List<Government> result = new List<Government>();
- for (int i = 0; i < array.Count; i++)
- {
- if (array[i] is Government)
- {
- ge = array[i];//Преобразование дочернего класса в родительский
- result.Add(ge);
- }
- //if (array[i].Dinasty == _dinasty)
- //{
- // result.Add(array[i]);
- //}
- }
- return result;
- }
- static List<Government> FindByRuler(List<Government> array, string _name)
- {
- List<Government> result = new List<Government>();
- for (int i = 0; i < array.Count; i++)
- {
- if (array[i].Name == _name)
- {
- result.Add(array[i]);
- }
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement