Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Поиск_преступника2
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- DataBase dataBase = new DataBase();
- dataBase.Work();
- }
- }
- class DataBase
- {
- private List<Criminal> _criminals = new List<Criminal>();
- public DataBase()
- {
- _criminals.Add(new Criminal("Альфонсе", "Капоне", "Габриэль", 85, 179, "Американец", false));
- _criminals.Add(new Criminal("Пабло", "Эскобар", "Гавирия", 70, 166, "Колумбиец", false));
- _criminals.Add(new Criminal("Александр", "Николаевич", "Спесивцев", 80, 170, "Русский", true));
- }
- public void Work()
- {
- ShowAllCriminals();
- SearchCriminal();
- }
- private void SearchCriminal()
- {
- int minGrowth = 30;
- int maxGrowth = 230;
- int minWeight = 40;
- int maxWeight = 300;
- Console.Write("\nВведите рост: ");
- int growth = Utility.GetInputNumber();
- Console.Write("Введите вес: ");
- int weight = Utility.GetInputNumber();
- Console.Write("Введите национальность: ");
- string nationality = Utility.GetInputText();
- if (growth <= minGrowth || growth >= maxGrowth && weight <= minWeight || weight >= maxWeight)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Ошибка ввода данных, введите данные еще раз");
- Console.ForegroundColor = ConsoleColor.White;
- SearchCriminal();
- }
- else
- {
- var filteredCriminal = _criminals.Where(criminal => criminal.Growth == growth
- && criminal.Weight == weight
- && criminal.Nationality.ToUpper() == nationality.ToUpper()
- && criminal.IsPrisoner == false);
- foreach (var criminal in filteredCriminal)
- {
- criminal.ShowDescription();
- }
- if (filteredCriminal.Count() == 0)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Преступник не найден в базе или уже под стражей");
- Console.ForegroundColor = ConsoleColor.White;
- }
- }
- }
- private void ShowAllCriminals()
- {
- Console.WriteLine("Преступники в базе:");
- foreach (var criminal in _criminals)
- {
- criminal.ShowDescription();
- }
- }
- }
- class Criminal
- {
- private string _name;
- private string _surname;
- private string _middleName;
- public Criminal(string name, string surname, string middleName, int weight, int growth, string nationality, bool isPrisoner)
- {
- _name = name;
- _surname = surname;
- _middleName = middleName;
- Weight = weight;
- Growth = growth;
- Nationality = nationality;
- IsPrisoner = isPrisoner;
- }
- public int Weight { get; private set; }
- public int Growth { get; private set; }
- public string Nationality { get; private set; }
- public bool IsPrisoner { get; private set; }
- public void ShowDescription()
- {
- Console.WriteLine($"ФИО: {_name} {_surname} {_middleName}|| Рост: {Growth} || Вес: {Weight} || Национальность: {Nationality} || Заключенный: {IsPrisoner}");
- }
- }
- class Utility
- {
- public static int GetInputNumber()
- {
- int number;
- while (int.TryParse(Console.ReadLine(), out number) == false)
- {
- Console.WriteLine("Введено не число, попробуйте еще раз: ");
- }
- return number;
- }
- public static string GetInputText()
- {
- string text = Console.ReadLine();
- foreach (char symbol in text)
- {
- if (char.IsLetter(symbol) == false || text == null)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Ошибка ввода данных, введите корректные данные: ");
- Console.ForegroundColor = ConsoleColor.White;
- GetInputText();
- return null;
- }
- }
- return text;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement