Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LinqTrain
- {
- class Program
- {
- public static void Main()
- {
- new Hospital().Work();
- }
- }
- public static class RandomStatic
- {
- static private Random _rand = new Random();
- static public int GetNext(int min, int max)
- {
- return _rand.Next(min, max);
- }
- }
- class FullName
- {
- public string Name { get; private set; }
- public string Surname { get; private set; }
- public string Patronymic { get; private set; }
- public FullName()
- {
- Name = new string[] { "Август", "Богдан", "Ваня", "Георгий", "Данил", "Женя" }[RandomStatic.GetNext(0, 6)];
- Surname = new string[] { "ЛУчников", "Захарчев", "Зайцев", "КУзнецов", "Столяров", "Коробничиков" }[RandomStatic.GetNext(0, 6)];
- Patronymic = new string[] { "Сергеевич", "Андреевич", "Саавич", "Арсеневич" }[RandomStatic.GetNext(0, 4)];
- }
- public string GetInfo()
- {
- return $"{Surname} {Name} {Patronymic}:";
- }
- }
- class Hospital
- {
- private List<Patient> _patients = new List<Patient>();
- public Hospital()
- {
- for (int i = 0; i < 30; i++)
- {
- _patients.Add(new Patient());
- }
- }
- public void Work()
- {
- bool isOpen = true;
- while (isOpen)
- {
- Console.Clear();
- Console.WriteLine("1 - Сортировка и вывод пациентов по ФИО \n2 - сортировка и вывод пациентов по возрасту \n3 - вывод пациентов по болезни");
- switch (Console.ReadKey().Key)
- {
- case ConsoleKey.D1:
- SortByFullName();
- break;
- case ConsoleKey.D2:
- SortByAge();
- break;
- case ConsoleKey.D3:
- SortByDisease();
- break;
- case ConsoleKey.Escape:
- isOpen = false;
- break;
- }
- }
- }
- private void SortByFullName()
- {
- Console.Clear();
- List<Patient> sortList = _patients.OrderBy(patients => patients.FullName.GetInfo()).ToList<Patient>();
- int count = 0;
- foreach (var item in sortList)
- {
- Console.WriteLine($"{count}: {item.GetInfo()}");
- count++;
- }
- Console.ReadKey();
- }
- private void SortByAge()
- {
- Console.Clear();
- var sortList = _patients.OrderBy(patients => patients.Age);
- int count = 0;
- foreach (var item in sortList)
- {
- Console.WriteLine($"{count}: {item.GetInfo()}");
- count++;
- }
- Console.ReadKey();
- }
- private void SortByDisease()
- {
- Console.Clear();
- Console.Write("Введите название болезни: ");
- string disease = Console.ReadLine();
- var sortList = _patients.Where(patient => patient.Disease.ToLower() == disease.ToLower());
- int count = 0;
- foreach (var item in sortList)
- {
- Console.WriteLine($"{count}: {item.GetInfo()}");
- count++;
- }
- Console.ReadKey();
- }
- }
- class Patient
- {
- public FullName FullName { get; private set; }
- public int Age { get; private set; }
- public string Disease { get; private set; }
- public Patient()
- {
- FullName = new FullName();
- Disease = new string[] { "ОРВИ", "Грипп", "Пнемония", "Ковид", "Перелом" }[RandomStatic.GetNext(0, 5)];
- Age = RandomStatic.GetNext(5, 75);
- }
- public string GetInfo()
- {
- return $"{FullName.GetInfo()} Возраст={Age}; Заболевание={Disease}";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement