SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Collections.Generic; | |
| 3 | using System.Linq; | |
| 4 | ||
| 5 | namespace LinqTrain | |
| 6 | {
| |
| 7 | class Program | |
| 8 | {
| |
| 9 | public static void Main() | |
| 10 | {
| |
| 11 | new Hospital().Work(); | |
| 12 | } | |
| 13 | } | |
| 14 | public static class RandomStatic | |
| 15 | {
| |
| 16 | static private Random _rand = new Random(); | |
| 17 | static public int GetNext(int min, int max) | |
| 18 | {
| |
| 19 | return _rand.Next(min, max); | |
| 20 | } | |
| 21 | } | |
| 22 | class FullName | |
| 23 | {
| |
| 24 | public string Name { get; private set; }
| |
| 25 | public string Surname { get; private set; }
| |
| 26 | public string Patronymic { get; private set; }
| |
| 27 | public FullName() | |
| 28 | {
| |
| 29 | Name = new string[] { "Август", "Богдан", "Ваня", "Георгий", "Данил", "Женя" }[RandomStatic.GetNext(0, 6)];
| |
| 30 | Surname = new string[] { "ЛУчников", "Захарчев", "Зайцев", "КУзнецов", "Столяров", "Коробничиков" }[RandomStatic.GetNext(0, 6)];
| |
| 31 | Patronymic = new string[] { "Сергеевич", "Андреевич", "Саавич", "Арсеневич" }[RandomStatic.GetNext(0, 4)];
| |
| 32 | } | |
| 33 | public string GetInfo() | |
| 34 | {
| |
| 35 | return $"{Surname} {Name} {Patronymic}:";
| |
| 36 | } | |
| 37 | } | |
| 38 | class Hospital | |
| 39 | {
| |
| 40 | private List<Patient> _patients = new List<Patient>(); | |
| 41 | public Hospital() | |
| 42 | {
| |
| 43 | for (int i = 0; i < 30; i++) | |
| 44 | {
| |
| 45 | _patients.Add(new Patient()); | |
| 46 | } | |
| 47 | } | |
| 48 | public void Work() | |
| 49 | {
| |
| 50 | bool isOpen = true; | |
| 51 | while (isOpen) | |
| 52 | {
| |
| 53 | Console.Clear(); | |
| 54 | Console.WriteLine("1 - Сортировка и вывод пациентов по ФИО \n2 - сортировка и вывод пациентов по возрасту \n3 - вывод пациентов по болезни");
| |
| 55 | switch (Console.ReadKey().Key) | |
| 56 | {
| |
| 57 | case ConsoleKey.D1: | |
| 58 | SortByFullName(); | |
| 59 | break; | |
| 60 | case ConsoleKey.D2: | |
| 61 | SortByAge(); | |
| 62 | break; | |
| 63 | case ConsoleKey.D3: | |
| 64 | - | SortByDisease(); |
| 64 | + | ShowPatientsWithСoncreteDisease(); |
| 65 | break; | |
| 66 | case ConsoleKey.Escape: | |
| 67 | isOpen = false; | |
| 68 | break; | |
| 69 | } | |
| 70 | } | |
| 71 | } | |
| 72 | private void SortByFullName() | |
| 73 | {
| |
| 74 | Console.Clear(); | |
| 75 | - | List<Patient> sortList = _patients.OrderBy(patients => patients.FullName.GetInfo()).ToList<Patient>(); |
| 75 | + | var patientListSortedByName = _patients.OrderBy(patients => patients.FullName.GetInfo()); |
| 76 | int count = 0; | |
| 77 | - | foreach (var item in sortList) |
| 77 | + | foreach (var patient in patientListSortedByName) |
| 78 | {
| |
| 79 | - | Console.WriteLine($"{count}: {item.GetInfo()}");
|
| 79 | + | Console.WriteLine($"{count}: {patient.GetInfo()}");
|
| 80 | count++; | |
| 81 | } | |
| 82 | Console.ReadKey(); | |
| 83 | } | |
| 84 | private void SortByAge() | |
| 85 | {
| |
| 86 | Console.Clear(); | |
| 87 | - | var sortList = _patients.OrderBy(patients => patients.Age); |
| 87 | + | var patientListSortedByAge = _patients.OrderBy(patients => patients.Age); |
| 88 | int count = 0; | |
| 89 | - | foreach (var item in sortList) |
| 89 | + | foreach (var patient in patientListSortedByAge) |
| 90 | {
| |
| 91 | - | Console.WriteLine($"{count}: {item.GetInfo()}");
|
| 91 | + | Console.WriteLine($"{count}: {patient.GetInfo()}");
|
| 92 | count++; | |
| 93 | } | |
| 94 | Console.ReadKey(); | |
| 95 | } | |
| 96 | - | private void SortByDisease() |
| 96 | + | private void ShowPatientsWithСoncreteDisease() |
| 97 | {
| |
| 98 | Console.Clear(); | |
| 99 | Console.Write("Введите название болезни: ");
| |
| 100 | string disease = Console.ReadLine(); | |
| 101 | - | var sortList = _patients.Where(patient => patient.Disease.ToLower() == disease.ToLower()); |
| 101 | + | var patientListWithСoncreteDisease = _patients.Where(patient => patient.Disease.ToLower() == disease.ToLower()); |
| 102 | int count = 0; | |
| 103 | - | foreach (var item in sortList) |
| 103 | + | foreach (var patient in patientListWithСoncreteDisease) |
| 104 | {
| |
| 105 | - | Console.WriteLine($"{count}: {item.GetInfo()}");
|
| 105 | + | Console.WriteLine($"{count}: {patient.GetInfo()}");
|
| 106 | count++; | |
| 107 | } | |
| 108 | Console.ReadKey(); | |
| 109 | } | |
| 110 | } | |
| 111 | class Patient | |
| 112 | {
| |
| 113 | public FullName FullName { get; private set; }
| |
| 114 | public int Age { get; private set; }
| |
| 115 | public string Disease { get; private set; }
| |
| 116 | ||
| 117 | public Patient() | |
| 118 | {
| |
| 119 | FullName = new FullName(); | |
| 120 | Disease = new string[] { "ОРВИ", "Грипп", "Пнемония", "Ковид", "Перелом" }[RandomStatic.GetNext(0, 5)];
| |
| 121 | Age = RandomStatic.GetNext(5, 75); | |
| 122 | } | |
| 123 | public string GetInfo() | |
| 124 | {
| |
| 125 | return $"{FullName.GetInfo()} Возраст={Age}; Заболевание={Disease}";
| |
| 126 | } | |
| 127 | } | |
| 128 | } |