Skip to content

Instantly share code, notes, and snippets.

@Dead-in-side
Created May 3, 2024 19:36
Show Gist options
  • Save Dead-in-side/0444839c95c70e7315452ea879e4ac9e to your computer and use it in GitHub Desktop.
Save Dead-in-side/0444839c95c70e7315452ea879e4ac9e to your computer and use it in GitHub Desktop.
namespace IJunior
{
public class Program
{
private static void Main(string[] args)
{
Hospital hospital = new Hospital();
hospital.Work();
}
}
public class Hospital
{
private List<Patient> _patients = new List<Patient>();
public void Work()
{
bool isWork = true;
AddPatients();
List<Patient> interimPatients = _patients;
while (isWork)
{
Console.WriteLine("Больница\n");
ShowPatients(interimPatients);
Console.WriteLine("Что вы хотите сделать");
Console.WriteLine((int)ConsoleCommand.SortByName + ". Отсортировать пациентов по имени");
Console.WriteLine((int)ConsoleCommand.SortByAge + ". Отсортировать пациентов по возрасту");
Console.WriteLine((int)ConsoleCommand.ShowPatientsWithDesease + ". Посмотреть пациентов с определенным заболеванием");
Console.WriteLine((int)ConsoleCommand.Exit + ". Выход");
if (int.TryParse(Console.ReadLine(), out int userInput))
{
switch (userInput)
{
case (int)ConsoleCommand.SortByName:
interimPatients = SortByName();
break;
case (int)ConsoleCommand.SortByAge:
interimPatients = SortByAge();
break;
case (int)ConsoleCommand.ShowPatientsWithDesease:
interimPatients = ShowPatientWithDisease();
break;
case (int)ConsoleCommand.Exit:
isWork = false;
break;
default:
interimPatients = _patients;
break;
}
}
Console.ReadLine();
Console.Clear();
}
}
private void AddPatients()
{
_patients.Add(new Patient("Mikola", "Передоз", 20));
_patients.Add(new Patient("Galya", "Вши", 10));
_patients.Add(new Patient("Genchik", "Вши", 10));
_patients.Add(new Patient("Malevich", "Передоз", 24));
_patients.Add(new Patient("Pedro", "Вывих тазобедренного сустава", 17));
_patients.Add(new Patient("Hulio", "Передоз", 22));
_patients.Add(new Patient("Pavlucha", "Простуда", 45));
_patients.Add(new Patient("Nastya", "Простуда", 4));
_patients.Add(new Patient("Nestle", "Кариес", 20));
_patients.Add(new Patient("Tess", "Чай", 3));
}
private List<Patient> SortByName() => _patients.OrderBy(patient => patient.Name).ToList();
private List<Patient> SortByAge() => _patients.OrderBy(patient => patient.Age).ToList();
private List<Patient> ShowPatientWithDisease()
{
Console.WriteLine("Введите заболевание: ");
string disease = Console.ReadLine();
var foundPatients = _patients.Where(patient => patient.Disease == disease).ToList();
return foundPatients;
}
private void ShowPatients(List<Patient> patients)
{
foreach (var patient in patients)
{
patient.ShowInfo();
}
}
private enum ConsoleCommand
{
SortByName = 1,
SortByAge,
ShowPatientsWithDesease,
Exit
}
}
public 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; }
public void ShowInfo()
{
Console.WriteLine(Name + " " + Age + " - " + Disease);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment