Advertisement
Dr_Max_Experience

Task 1

Jul 13th, 2022
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ООП
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Archive archive = new Archive( new List<Perpetrator> {
  14.                 new Perpetrator("Николай Дмитриевич", false, 165, 70, "русский"),
  15.                 new Perpetrator("Иван Иванович", false, 175, 75, "русский"),
  16.                 new Perpetrator("Дмитрий Владимирович", false, 175, 75, "русский"),
  17.                 new Perpetrator("Афанасий Афанасиевич", false, 170, 90, "беларус"),
  18.                 new Perpetrator("Армен Арменович", true, 180, 80, "армянин"),
  19.                 new Perpetrator("Дмитрий Николаевич", false, 180, 80, "русский"),
  20.                 new Perpetrator("Артём Владимирович", true, 175, 80, "беларус"),
  21.             });
  22.  
  23.             archive.IsUse();
  24.         }
  25.     }
  26.  
  27.     class Perpetrator
  28.     {
  29.         public string Initials { get; private set; }
  30.         public bool IsLockedUp { get; private set; }
  31.         public int Growth { get; private set; }
  32.         public int Weight { get; private set; }
  33.         public string Ethnicity { get; private set; }
  34.  
  35.         public Perpetrator(string initials, bool isLockedUp, int growth, int weight, string ethnicity)
  36.         {
  37.             Initials = initials;
  38.             IsLockedUp = isLockedUp;
  39.             Growth = growth;
  40.             Weight = weight;
  41.             Ethnicity = ethnicity;
  42.         }
  43.  
  44.         public void ShowInfo()
  45.         {
  46.             Console.WriteLine($"{Initials} | Заключён: {IsLockedUp} | Рост: {Growth} | Вес: {Weight} | {Ethnicity}");
  47.         }
  48.     }
  49.  
  50.     class Archive
  51.     {
  52.         List<Perpetrator> _perpetrators;
  53.  
  54.         public Archive(List<Perpetrator> perpetrator)
  55.         {
  56.             _perpetrators = perpetrator;
  57.         }
  58.  
  59.         public void IsUse()
  60.         {
  61.             bool isOpen = true;
  62.             int growth;
  63.             int weight;
  64.             string ethnicity;
  65.  
  66.             while (isOpen)
  67.             {
  68.                 Console.Clear();
  69.                 Console.WriteLine("Поиск преступника из архива");
  70.                 growth = CorrectInput("рост: ");
  71.                 weight = CorrectInput("вес: ");
  72.                 Console.Write("Введите национальность: ");
  73.  
  74.                 ethnicity = Console.ReadLine();
  75.  
  76.                 var results = from Perpetrator perpetrator in _perpetrators where perpetrator.IsLockedUp == false where perpetrator.Growth == growth where perpetrator.Weight == weight where perpetrator.Ethnicity == ethnicity select perpetrator;
  77.  
  78.                 Console.WriteLine("Список найденых преступников: ");
  79.  
  80.                 foreach (var result in results)
  81.                 {
  82.                     result.ShowInfo();
  83.                 }
  84.  
  85.                 Console.ReadKey();
  86.             }
  87.         }
  88.  
  89.         private int CorrectInput(string label)
  90.         {
  91.             bool correctImput = false;
  92.             int correctNumber = 0;
  93.  
  94.             while (correctImput == false)
  95.             {
  96.                 Console.Write($"Введите {label}");
  97.                 string userInput = Console.ReadLine();
  98.                 correctImput = int.TryParse(userInput, out correctNumber);
  99.             }
  100.  
  101.             return correctNumber;
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement