Created
August 8, 2023 23:35
-
-
Save ShamilAitov/ad3b8b97960d632ca8ed02be5beade9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace LINQ3Задание | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Hospital hospital = new Hospital(); | |
hospital.PlayProgram(); | |
} | |
} | |
class Patient | |
{ | |
public Patient(string fullName, int age, string diseases) | |
{ | |
FullName = fullName; | |
Age = age; | |
Diseases = diseases; | |
} | |
public string FullName { get; private set; } | |
public int Age { get; private set; } | |
public string Diseases { get; private set; } | |
public void ShowInfo() | |
{ | |
Console.WriteLine($"{FullName} ({Age} лет) - {Diseases}"); | |
} | |
} | |
class Hospital | |
{ | |
private List<Patient> _patients = new List<Patient>(); | |
public Hospital() | |
{ | |
FillPatients(); | |
} | |
public void PlayProgram() | |
{ | |
const string SortingFullNameСommand = "1"; | |
const string SortingAgeСommand = "2"; | |
const string FindDiseasesСommand = "3"; | |
bool isWorking = true; | |
string userInput; | |
while (isWorking) | |
{ | |
Console.Write($"Ты в больнице:\n{SortingFullNameСommand} - Отсортировать всех больных по фио\n" + | |
$"{SortingAgeСommand} - Отсортировать всех больных по возрасту\n" + | |
$"{FindDiseasesСommand} - Вывести больных с определенным заболеванием\nВведите команду:"); | |
userInput = Console.ReadLine(); | |
switch (userInput) | |
{ | |
case SortingFullNameСommand: | |
var sortingFullName = _patients.OrderBy(Patient => Patient.FullName).ToList(); | |
ShowPatients(sortingFullName); | |
break; | |
case SortingAgeСommand: | |
var sortingAge = _patients.OrderBy(Patient => Patient.Age).ToList(); | |
ShowPatients(sortingAge); | |
break; | |
case FindDiseasesСommand: | |
FindDiseases(); | |
break; | |
default: | |
Console.WriteLine("Попробуйте еще раз!"); | |
break; | |
} | |
Console.ReadKey(); | |
Console.Clear(); | |
} | |
} | |
private void FindDiseases() | |
{ | |
string introductionDisease; | |
Console.Write("Введите заболевание: "); | |
introductionDisease = Console.ReadLine(); | |
var findDiseases = _patients.Where(Patient => Patient.Diseases.ToUpper() == introductionDisease.ToUpper()).ToList(); | |
ShowPatients(findDiseases); | |
} | |
private void FillPatients() | |
{ | |
_patients.Add(new Patient("Атталь Аберфорт", 38, "Бронхит")); | |
_patients.Add(new Patient("Гарибальди Адриан", 30, "Пневмония")); | |
_patients.Add(new Patient("Макрон Арчибальд", 27, "Трахеит")); | |
_patients.Add(new Patient("Бардо Бруно", 29, "Абсцесс")); | |
_patients.Add(new Patient("Герарди Киллиан", 39, "Бронхит")); | |
_patients.Add(new Patient("Валери Генри", 37, "Пневмония")); | |
} | |
private void ShowPatients(List<Patient> patients) | |
{ | |
if (patients.Any()) | |
{ | |
foreach (var patient in patients) | |
{ | |
patient.ShowInfo(); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("Список пуст!"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment