Skip to content

Instantly share code, notes, and snippets.

@Dnk095
Last active July 19, 2024 09:19
Show Gist options
  • Save Dnk095/d6fa90b003283b84f6d02f42b5fc2f02 to your computer and use it in GitHub Desktop.
Save Dnk095/d6fa90b003283b84f6d02f42b5fc2f02 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
namespace _7_3
{
internal class Program
{
static void Main()
{
Hospital hospital = new Hospital();
hospital.Work();
}
}
class Patient
{
public Patient(string name, string disease, int age)
{
Name = name;
Disease = disease;
Age = age;
}
public string Name { get; }
public string Disease { get; }
public int Age { get; }
}
class Hospital
{
private List<Patient> _patients;
public Hospital()
{
_patients = new List<Patient>();
Fill();
}
public void Work()
{
const string CommandSortAsAge = "1";
const string CommandSortAsDisease = "2";
const string CommandShowWithDisease = "3";
const string CommandExit = "4";
bool isWorking = true;
while (isWorking)
{
Console.ReadKey();
Console.Clear();
Console.WriteLine("Список больных: ");
ShowAllPatients(_patients);
Console.WriteLine("\nВыберете команду:");
Console.WriteLine($"{CommandSortAsAge} - сортировать пацинтов по возрасту" +
$"\n{CommandSortAsDisease} - сортировать пацинтов по заболеванию" +
$"\n{CommandShowWithDisease} - показать всех больных с определенным заболеванием" +
$"\n{CommandExit} - выход");
string inputData = Console.ReadLine();
while (string.IsNullOrEmpty(inputData) && int.TryParse(inputData, out int number) == false && number <= 0)
{
Console.WriteLine("Некорректный ввод данных попробуйте снова");
inputData = Console.ReadLine();
}
switch (inputData)
{
case CommandSortAsAge:
SortAsAge();
break;
case CommandSortAsDisease:
SortAsDisease();
break;
case CommandShowWithDisease:
ShowWithDisease();
break;
default:
isWorking = false;
break;
}
}
}
private void ShowAllPatients(List<Patient> patients)
{
foreach (Patient patient in patients)
Console.WriteLine($"{patient.Name} - {patient.Age} - {patient.Disease}");
}
private void Fill()
{
_patients.Add(new Patient("Боб", "чума", 45));
_patients.Add(new Patient("Джо", "ангина", 30));
_patients.Add(new Patient("Карл", "оспа", 50));
_patients.Add(new Patient("Дэн", "корь", 12));
_patients.Add(new Patient("Дэнчик", "чума", 47));
_patients.Add(new Patient("Кларк", "орв", 90));
_patients.Add(new Patient("Достя", "корона", 120));
_patients.Add(new Patient("Фрик", "грыжа", 10));
_patients.Add(new Patient("Кевин", "ветрянка", 73));
_patients.Add(new Patient("Руся", "ангина", 38));
}
private void SortAsAge()
{
List<Patient> patients = _patients.OrderBy(patiens => patiens.Age).ToList();
ShowAllPatients(patients);
}
private void SortAsDisease()
{
List<Patient> patients = _patients.OrderBy(patiens => patiens.Disease).ToList();
ShowAllPatients(patients);
}
private void ShowWithDisease()
{
Console.WriteLine("Введите заболевание");
string inputDisease = Console.ReadLine();
while (string.IsNullOrEmpty(inputDisease))
{
Console.WriteLine("Пустая строка попробуйте снова");
inputDisease = Console.ReadLine();
}
List<Patient> patients = _patients.Where(patiens => patiens.Disease == inputDisease).
OrderBy(patiens => patiens.Disease).ToList();
if (patients.Count > 0)
ShowAllPatients(patients);
else
Console.WriteLine("Нет больных с таким заболеванием");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment