Anonim_999

Anarchy in the hospital

Nov 2nd, 2021 (edited)
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApp2
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Hospital hospital = new Hospital();
  13.             hospital.StartWork();
  14.         }
  15.     }
  16.  
  17.     class Hospital
  18.     {
  19.         private List<Patient> _patients;
  20.  
  21.         public Hospital()
  22.         {
  23.             _patients = new List<Patient>
  24.             {
  25.                 new Patient("Королева Варвара Ильинична"),
  26.                 new Patient("Осипов Георгий Игоревич"),
  27.                 new Patient("Андреева Мия Ивановна"),
  28.                 new Patient("Чумаков Степан Никитич"),
  29.                 new Patient("Скворцов Тимур Максимович"),
  30.                 new Patient("Попов Лев Андреевич"),
  31.                 new Patient("Кондратьева Виктория Владиславовна"),
  32.                 new Patient("Сахарова Виктория Данииловна"),
  33.                 new Patient("Коновалов Сергей Маркович"),
  34.                 new Patient("Нечаев Марк Максимович")
  35.             };
  36.         }
  37.  
  38.         public void StartWork()
  39.         {
  40.             bool isWorking = true;
  41.             string userInput;
  42.  
  43.             while (isWorking)
  44.             {
  45.                 Console.WriteLine("Нажмите любую клавишу, чтобы продолжить...");
  46.                 Console.ReadKey();
  47.                 Console.Clear();
  48.                 Console.WriteLine("Меню:\n1.Отсортировать всех больных по ФИО\n2.Отсортировать всех больных по возрасту\n3.Вывести больных с определенным заболеванием\n4.Выход");
  49.                 userInput = Console.ReadLine();
  50.  
  51.                 switch (userInput)
  52.                 {
  53.                     case "1":
  54.                         ShowSortByFullName();
  55.                         break;
  56.                     case "2":
  57.                         ShowSortByAge();
  58.                         break;
  59.                     case "3":
  60.                         Console.Write("\nВведите название болезни: ");
  61.                         userInput = Console.ReadLine();
  62.                         ShowPatientByDisease(userInput);
  63.                         break;
  64.                     case "4":
  65.                         isWorking = false;
  66.                         break;
  67.                     default:
  68.                         Console.WriteLine("Нет такой команды!");
  69.                         break;
  70.                 }
  71.             }
  72.         }
  73.  
  74.         private void ShowSortByFullName()
  75.         {
  76.             var patients = _patients.OrderBy(patient => patient.FullName);
  77.             ShowPatients(patients);
  78.         }
  79.  
  80.         private void ShowSortByAge()
  81.         {
  82.             var patients = _patients.OrderBy(patient => patient.Age);
  83.             ShowPatients(patients);
  84.         }
  85.  
  86.         private void ShowPatientByDisease(string disease)
  87.         {
  88.             var patients = _patients.Where(patient => patient.Disease == disease);
  89.             ShowPatients(patients);
  90.         }
  91.  
  92.         private void ShowPatients(IEnumerable<Patient> patients)
  93.         {
  94.             foreach (var patient in patients)
  95.             {
  96.                 patient.ShowInfo();
  97.             }
  98.         }
  99.     }
  100.  
  101.     class Patient
  102.     {
  103.         public string FullName { get; private set; }
  104.         public int Age { get; private set; }
  105.         public string Disease { get; private set; }
  106.  
  107.         public Patient(string fullName)
  108.         {
  109.             Random random = new Random();
  110.             List<string> diseases = new List<string> { "Гайморит", "Альцгеймер", "Covid-19", "ВИЧ/СПИД" };
  111.             FullName = fullName;
  112.             Age = random.Next(6, 100);
  113.             Disease = diseases[random.Next(0, diseases.Count)];
  114.         }
  115.  
  116.         public void ShowInfo()
  117.         {
  118.             Console.WriteLine($"ФИО: {FullName} || Возраст: {Age}\nЗаболевания: {Disease}\n");
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment