Created
August 6, 2023 23:34
-
-
Save ShamilAitov/b5a2d5b529dfa4802df28ce99ade0594 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace LINQ1Задание | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Search search = new Search(); | |
search.PlayProgram(); | |
} | |
} | |
class Search | |
{ | |
private List<Criminal> _criminals = new List<Criminal>(); | |
public Search() | |
{ | |
FillCriminals(); | |
} | |
public void PlayProgram() | |
{ | |
bool isWorking = true; | |
while (isWorking) | |
{ | |
Console.Write("Привет, ты попал в детективное агенство!\nВведи (рост, вес, нацианальность разыскиваемых), начнем с роста: "); | |
int enteringGrowth = GetNumber(); | |
Console.Write("Введи вес: "); | |
int weightInput = GetNumber(); | |
Console.Write("Введи нацианальность: "); | |
string enteringNationality = Console.ReadLine(); | |
var filteredCriminals = _criminals.Where(Criminal => Criminal.Height == enteringGrowth). | |
Where(Criminal => Criminal.Weight == weightInput). | |
Where(Criminal => Criminal.Nationalitye.ToUpper() == enteringNationality.ToUpper()). | |
Where(Criminal => Criminal.InCustody == false); | |
if (filteredCriminals.Any()) | |
{ | |
foreach (var criminal in filteredCriminals) | |
{ | |
criminal.ShowInfo(); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("Ничего не найдено, попробуйте еще раз!"); | |
} | |
Console.ReadKey(); | |
Console.Clear(); | |
} | |
} | |
private int GetNumber() | |
{ | |
int number; | |
while (int.TryParse(Console.ReadLine(), out number) == false) | |
{ | |
Console.Write("Нужно ввести именно число, попробуйте еще раз: "); | |
} | |
return number; | |
} | |
private void FillCriminals() | |
{ | |
_criminals.Add(new Criminal("Атталь Аберфорт", true, 180, 76, "Француз", "Cмотрящий")); | |
_criminals.Add(new Criminal("Гарибальди Адриан", false, 180, 76, "Изид", "Вор в законе")); | |
_criminals.Add(new Criminal("Макрон Арчибальд", false, 170, 70, "Грузин", "Вор в законе")); | |
_criminals.Add(new Criminal("Бардо Бруно", false, 170, 70, "Поляк", "Мужик")); | |
_criminals.Add(new Criminal("Валери Генри", false, 170, 70, "Грузин", "Мужик")); | |
_criminals.Add(new Criminal("Герарди Киллиан", true, 170, 70, "Поляк", "Вор в законе")); | |
} | |
} | |
class Criminal | |
{ | |
public Criminal(string fullName, bool inCustody, int height, int weight, string nationalitye, string status) | |
{ | |
FullName = fullName; | |
InCustody = inCustody; | |
Height = height; | |
Weight = weight; | |
Nationalitye = nationalitye; | |
Status = status; | |
} | |
public string FullName { get; private set; } | |
public bool InCustody { get; private set; } | |
public int Height { get; private set; } | |
public int Weight { get; private set; } | |
public string Nationalitye { get; private set; } | |
public string Status { get; private set; } | |
public void ShowInfo() | |
{ | |
if (InCustody) | |
{ | |
Console.WriteLine($"Преступник: {FullName} - Рост ({Height} см.), Вес ({Weight} кг.), Национальность({Nationalitye}), Статус ({Status}) - под стражей."); | |
} | |
else | |
{ | |
Console.WriteLine($"Преступник: {FullName} - Рост ({Height} см.), Вес ({Weight} кг.), Национальность({Nationalitye}), Статус ({Status}) - на воле."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment