Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LinqTask1FindCriminal
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- DetectiveDepartment detectiveDepartment = new DetectiveDepartment();
- detectiveDepartment.Work();
- }
- }
- public class DetectiveDepartment
- {
- private List<Criminal> _criminals;
- public DetectiveDepartment()
- {
- FillCriminals();
- }
- public void Work()
- {
- const char CommandExit = 'q';
- bool isWorking = true;
- int minimumHeight;
- int maximumHeight;
- int minimumWidth;
- int maximumWidth;
- string nationality;
- while (isWorking)
- {
- ShowCriminals(_criminals);
- Console.Write("\nВведите минимальный рост преступника: ");
- minimumHeight = ReadInt();
- Console.Write("Введите максимальный рост преступника: ");
- maximumHeight = ReadInt();
- Console.Write("Введите минимальный вес преступника: ");
- minimumWidth = ReadInt();
- Console.Write("Введите максимальный вес преступника: ");
- maximumWidth = ReadInt();
- Console.Write("Введите национальность преступника: ");
- nationality = Console.ReadLine();
- Console.WriteLine();
- var filteredCriminals = _criminals.Where(criminal =>
- criminal.Height >= minimumHeight && criminal.Height <= maximumHeight &&
- criminal.Width >= minimumWidth && criminal.Width <= maximumWidth &&
- criminal.Nationality == nationality && criminal.IsInPrison == false).ToList();
- if (filteredCriminals.Count() == 0)
- {
- Console.WriteLine("Нет свободных преступников, подходящих под введенные требования");
- }
- else
- {
- ShowCriminals(filteredCriminals);
- }
- Console.WriteLine($"\nДля продолжения нажмите любую клавишу или {CommandExit} для выхода");
- if (Console.ReadKey().KeyChar == CommandExit)
- isWorking = false;
- Console.Clear();
- }
- }
- private void ShowCriminals(List<Criminal> criminals)
- {
- Console.WriteLine("Преступники:");
- foreach (var criminal in criminals)
- {
- criminal.ShowInfo();
- }
- }
- private void FillCriminals()
- {
- _criminals = new List<Criminal>
- {
- new Criminal("gdfsgdfg", true, 180, 80, "русский"),
- new Criminal("dfsdfsd", false, 170, 100, "узбек"),
- new Criminal("bfgnbfn", false, 186, 90, "таджик"),
- new Criminal("bnvncvbn", true, 184, 70, "русский"),
- new Criminal("gdfxvxcvxcsgdfg", false, 180, 60, "еврей"),
- new Criminal("xcvzxcc", false, 189, 77, "негр"),
- new Criminal("xvvxv", false, 160, 84, "узбек"),
- new Criminal("nfhnn", true, 166, 86, "русский"),
- new Criminal("dgdfgdg", false, 172, 89, "узбек"),
- };
- }
- private static int ReadInt()
- {
- int inputNumber;
- while (int.TryParse(Console.ReadLine(), out inputNumber) == false)
- {
- Console.Write("Это не число, попробуйте еще раз: ");
- }
- return inputNumber;
- }
- }
- public class Criminal
- {
- public Criminal(string name, bool isInPrison, int height, int width, string nationality)
- {
- Name = name;
- IsInPrison = isInPrison;
- Height = height;
- Width = width;
- Nationality = nationality;
- }
- public string Name { get; private set; }
- public bool IsInPrison { get; private set; }
- public int Height { get; private set; }
- public int Width { get; private set; }
- public string Nationality { get; private set; }
- public void ShowInfo()
- {
- Console.WriteLine($"{Name}: рост {Height} см, вес {Width} кг, национальность: {Nationality}, в тюрьме: {IsInPrison}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement