Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Task51
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- DataBase dataBase = new DataBase();
- dataBase.Work();
- }
- }
- class DataBase
- {
- private List<Criminal> _criminals;
- public DataBase()
- {
- _criminals = new List<Criminal>();
- _criminals.Add(new Criminal("Лавров","Алексей", "Иванович", true, 160, 65, "Роговин"));
- _criminals.Add(new Criminal("Сидоров", "Виктор", "Андреевич", false, 181, 93, "Перкек"));
- _criminals.Add(new Criminal("Шульц", "Александр", "Измаилович", false, 174, 78, "Коми"));
- _criminals.Add(new Criminal("Варналов", "Николай", "Владимирович", true, 156, 60, "Налак"));
- _criminals.Add(new Criminal("Швалов", "Владимир", "Сергеевич", true, 178, 110, "Новоряк"));
- _criminals.Add(new Criminal("Капустин", "Пётр", "Дмитриевич", true, 192, 98, "Ладык"));
- }
- public void Work()
- {
- int growth;
- int weight;
- string nationality;
- string userInput;
- string requestGrowthWeightNationality =
- "Введите рост, вес и национальность подозреваемого.";
- string requestGrowth =
- "Введите рост: ";
- string requestWeight =
- "Введите вес: ";
- string requestNationality =
- "Введите национальность: ";
- string errorInputData =
- "Ошибка. Вы велли данные некоректно. ";
- string goodbye =
- "До свидания.";
- const string answerExitYes =
- "Да";
- bool isExit = false;
- while (isExit != true)
- {
- Console.WriteLine(requestGrowthWeightNationality);
- Console.Write(requestGrowth);
- growth = UserUtils.GetInt(requestGrowth);
- Console.Write(requestWeight);
- weight = UserUtils.GetInt(requestWeight);
- Console.Write(requestNationality);
- nationality = UserUtils.GetString(requestNationality);
- if (growth == 0 || weight == 0 || nationality == null)
- {
- Console.WriteLine(errorInputData);
- }
- else
- {
- var foundPeople = from people in _criminals
- where people.Growth <= growth
- && people.Weight <= weight
- && people.Nationality.ToLower() == nationality.ToLower()
- && people.IsCondemned == false
- select people;
- foreach (var people in foundPeople)
- {
- people.ShowCriminal();
- }
- }
- Console.WriteLine(
- "1 - чтобы выйти.\n" +
- "Любая другая кнопка, продолжение работы программы.");
- userInput = Console.ReadLine().ToLower();
- if (userInput == answerExitYes)
- {
- isExit = true;
- Console.WriteLine(goodbye);
- }
- }
- }
- }
- class Criminal
- {
- private string _surname;
- private string _name;
- private string _middleName;
- public bool IsCondemned { get; private set; }
- public int Growth { get; private set; }
- public int Weight { get; private set; }
- public string Nationality { get; private set; }
- public Criminal(string surname, string name, string middleName, bool isCondemned, int growth, int weight, string nationality)
- {
- _surname = surname;
- _name = name;
- _middleName = middleName;
- IsCondemned = isCondemned;
- Growth = growth;
- Weight = weight;
- Nationality = nationality;
- }
- public void ShowCriminal()
- {
- Console.WriteLine(
- $"ФИО ----------------- {_surname} {_name} {_middleName}\n" +
- $"Заключён под стражу - {IsCondemned}\n" +
- $"Рост ---------------- {Growth}\n" +
- $"Вес ----------------- {Weight}\n" +
- $"Национальность ------ {Nationality}");
- }
- }
- static class UserUtils
- {
- public static int GetInt(string requestInputNumber)
- {
- string errorConversion = "Ошибка,вы вели не цифры! Попробуйте снова.";
- string userInput;
- bool resultConverted = false;
- int number = 0;
- while (resultConverted == false)
- {
- Console.Write(requestInputNumber);
- userInput = Console.ReadLine();
- resultConverted = int.TryParse(userInput, out int numberConvert);
- if (resultConverted != true)
- Console.WriteLine(errorConversion);
- else
- number = numberConvert;
- }
- return number;
- }
- public static string GetString(string requestNationality)
- {
- int errorCounter;
- string error =
- "В написании нужно использовать только буквы!";
- string userInput = null;
- bool correctWritten = false;
- while (correctWritten == false)
- {
- errorCounter = 0;
- Console.Write(requestNationality);
- userInput = Console.ReadLine();
- foreach (char symbol in userInput)
- {
- if (char.IsLetter(symbol) == false)
- {
- Console.WriteLine(error);
- errorCounter++;
- }
- }
- if (errorCounter == 0)
- {
- correctWritten = true;
- }
- }
- return userInput;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement