Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace CSLight
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- PersonBase person = new PersonBase();
- person.ShowBanditsInfo();
- }
- }
- class PersonBase
- {
- private List<Person> _bandits;
- public PersonBase()
- {
- GenerateBandits();
- }
- public void ShowBanditsInfo()
- {
- Console.WriteLine("Введите рост:");
- float height = SetFloat();
- Console.WriteLine("Введите вес:");
- float weight = SetFloat();
- Console.WriteLine("Введите национальность");
- string nationality = Console.ReadLine();
- var filteredList = _bandits.Where(bandit => bandit.Height > height && bandit.Weight > weight && bandit.Nationality == nationality && bandit.IsFree);
- Console.WriteLine($"Найденые совпадения:");
- ShowList(filteredList);
- Console.ReadKey();
- }
- private void ShowList(IEnumerable<Person> list)
- {
- foreach (Person person in list)
- {
- Console.WriteLine($"{person.Surname} {person.Name} {person.Patronymic}");
- }
- }
- private float SetFloat()
- {
- bool isRunnig = true;
- float value = 0;
- while (isRunnig)
- {
- string userInput = Console.ReadLine();
- if (float.TryParse(userInput, out float result))
- {
- value = result;
- isRunnig = false;
- }
- else
- {
- Console.WriteLine("Неверный ввод");
- }
- }
- return value;
- }
- private void GenerateBandits()
- {
- PersonCreator creator = new PersonCreator();
- int dataBaseCapacity = 20;
- _bandits = new List<Person>();
- for (int i = 0; i < dataBaseCapacity; i++)
- {
- _bandits.Add(creator.CreatePerson());
- }
- }
- }
- class PersonCreator
- {
- private List<string> _names;
- private List<string> _surnames;
- private List<string> _patronymic;
- private List<string> _nationalities;
- public PersonCreator()
- {
- InitNames();
- InitSurnames();
- InitPatronymics();
- InitNationalities();
- }
- public Person CreatePerson()
- {
- int minHeight = 1;
- int maxHeight = 2;
- int minWeight = 56;
- int maxWeight = 100;
- string name = GetRandomValue(_names);
- string surname = GetRandomValue(_surnames);
- string patronymic = GetRandomValue(_patronymic);
- string nationalities = GetRandomValue(_nationalities);
- float weight = UserUtils.GenerateRandomValue(minWeight, maxWeight) + (float)UserUtils.GenerateRandomDouble();
- float height = UserUtils.GenerateRandomValue(minHeight, maxHeight) + (float)UserUtils.GenerateRandomDouble();
- return new Person(name, surname, patronymic, height, weight, nationalities, SetStatus());
- }
- private void InitSurnames()
- {
- _surnames = new List<string>();
- _surnames.Add("Смирнов");
- _surnames.Add("Иванов");
- _surnames.Add("Кузнецов");
- _surnames.Add("Попов");
- _surnames.Add("Соколов");
- _surnames.Add("Лебедев");
- _surnames.Add("Козлов");
- _surnames.Add("Новиков");
- _surnames.Add("Морозов");
- _surnames.Add("Козлов");
- _surnames.Add("Волков");
- }
- private void InitPatronymics()
- {
- _patronymic = new List<string>();
- _patronymic.Add("Максимович");
- _patronymic.Add("Михаилович");
- _patronymic.Add("Александрович");
- _patronymic.Add("Дмитриевич");
- _patronymic.Add("Денисович");
- _patronymic.Add("Ильич");
- _patronymic.Add("Андреевич");
- _patronymic.Add("Артемович");
- _patronymic.Add("Иванович");
- _patronymic.Add("Алексеевич");
- _patronymic.Add("Никитич");
- }
- private void InitNames()
- {
- _names = new List<string>();
- _names.Add("Максим");
- _names.Add("Михаил");
- _names.Add("Александр");
- _names.Add("Дмитрий");
- _names.Add("Денис");
- _names.Add("Илья");
- _names.Add("Андрей");
- _names.Add("Артем");
- _names.Add("Иван");
- _names.Add("Алексей");
- _names.Add("Никита");
- }
- private void InitNationalities()
- {
- _nationalities = new List<string>();
- _nationalities.Add("Русский");
- _nationalities.Add("Не русский");
- }
- private string GetRandomValue(List<string> values)
- {
- int randomId = UserUtils.GenerateRandomValue(values.Count);
- return values[randomId];
- }
- private bool SetStatus()
- {
- int chance = 50;
- int maxChance = 100;
- return UserUtils.GenerateRandomValue(maxChance) > chance;
- }
- }
- class Person
- {
- public Person(string name, string surname, string patronymic, float height, float weight, string nationality, bool isFree)
- {
- Name = name;
- Surname = surname;
- Patronymic = patronymic;
- Height = height;
- Weight = weight;
- Nationality = nationality;
- IsFree = isFree;
- }
- public string Name { get; private set; }
- public string Surname { get; private set; }
- public string Patronymic { get; private set; }
- public float Height { get; private set; }
- public float Weight { get; private set; }
- public string Nationality { get; private set; }
- public bool IsFree { get; private set; }
- }
- static class UserUtils
- {
- private static Random s_random = new Random();
- public static int GenerateRandomValue(int maxValue)
- {
- return s_random.Next(maxValue);
- }
- public static int GenerateRandomValue(int minValue, int maxValue)
- {
- return s_random.Next(minValue, maxValue);
- }
- public static double GenerateRandomDouble()
- {
- return s_random.NextDouble();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement