Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Linq;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Hospital hospital = new Hospital();
- hospital.StartWork();
- }
- }
- class Hospital
- {
- private List<Patient> _patients;
- public Hospital()
- {
- _patients = new List<Patient>
- {
- new Patient("Королева Варвара Ильинична"),
- new Patient("Осипов Георгий Игоревич"),
- new Patient("Андреева Мия Ивановна"),
- new Patient("Чумаков Степан Никитич"),
- new Patient("Скворцов Тимур Максимович"),
- new Patient("Попов Лев Андреевич"),
- new Patient("Кондратьева Виктория Владиславовна"),
- new Patient("Сахарова Виктория Данииловна"),
- new Patient("Коновалов Сергей Маркович"),
- new Patient("Нечаев Марк Максимович")
- };
- }
- public void StartWork()
- {
- bool isWorking = true;
- string userInput;
- while (isWorking)
- {
- Console.WriteLine("Нажмите любую клавишу, чтобы продолжить...");
- Console.ReadKey();
- Console.Clear();
- Console.WriteLine("Меню:\n1.Отсортировать всех больных по ФИО\n2.Отсортировать всех больных по возрасту\n3.Вывести больных с определенным заболеванием\n4.Выход");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- ShowSortByFullName();
- break;
- case "2":
- ShowSortByAge();
- break;
- case "3":
- Console.Write("\nВведите название болезни: ");
- userInput = Console.ReadLine();
- ShowPatientByDisease(userInput);
- break;
- case "4":
- isWorking = false;
- break;
- default:
- Console.WriteLine("Нет такой команды!");
- break;
- }
- }
- }
- private void ShowSortByFullName()
- {
- var patients = _patients.OrderBy(patient => patient.FullName);
- ShowPatients(patients);
- }
- private void ShowSortByAge()
- {
- var patients = _patients.OrderBy(patient => patient.Age);
- ShowPatients(patients);
- }
- private void ShowPatientByDisease(string disease)
- {
- var patients = _patients.Where(patient => patient.Disease == disease);
- ShowPatients(patients);
- }
- private void ShowPatients(IEnumerable<Patient> patients)
- {
- foreach (var patient in patients)
- {
- patient.ShowInfo();
- }
- }
- }
- class Patient
- {
- public string FullName { get; private set; }
- public int Age { get; private set; }
- public string Disease { get; private set; }
- public Patient(string fullName)
- {
- Random random = new Random();
- List<string> diseases = new List<string> { "Гайморит", "Альцгеймер", "Covid-19", "ВИЧ/СПИД" };
- FullName = fullName;
- Age = random.Next(6, 100);
- Disease = diseases[random.Next(0, diseases.Count)];
- }
- public void ShowInfo()
- {
- Console.WriteLine($"ФИО: {FullName} || Возраст: {Age}\nЗаболевания: {Disease}\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment