Created
May 29, 2024 14:50
-
-
Save EreminAndrei/227dcc987c1a06743070f16a9939769a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 project4 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
HospitalDatabase hospitalDatabase = new HospitalDatabase(); | |
hospitalDatabase.Work(); | |
} | |
} | |
class UserUtils | |
{ | |
private static Random s_random = new Random(); | |
public static int GenerateRandomNumber(int min, int max) | |
{ | |
return s_random.Next(min, max); | |
} | |
} | |
class HospitalDatabase | |
{ | |
private List<Patient> _patients; | |
public HospitalDatabase() | |
{ | |
int maxNumberOfPatients = 25; | |
int minAge = 0; | |
int maxAge = 100; | |
List<Patient> patients = new List<Patient>(); | |
string[] names = new string[] { "Билл", "Джон", "Джек", "Кларк", "Питер", "Виктор", "Дик", "Майкл" }; | |
string[] diagnoses = new string[] { "Корь", "ОРВИ", "Грипп", "Краснуха", "Перелом", "Гепатит", "Ковид", "Мененгит", "Ветрянка" }; | |
for (int i = 0; i < maxNumberOfPatients; i++) | |
{ | |
patients.Add(new Patient(names[UserUtils.GenerateRandomNumber(0, names.Length)], UserUtils.GenerateRandomNumber(minAge, maxAge), diagnoses[UserUtils.GenerateRandomNumber(0, diagnoses.Length)])); | |
} | |
_patients = patients; | |
} | |
public void Work() | |
{ | |
const string CommandSortByName = "1"; | |
const string CommandSortByAge = "2"; | |
const string CommandShowPatientsWithDiagnisis = "3"; | |
const string CommandExit = "4"; | |
Console.WriteLine("Добро пожаловать в базу больницы."); | |
Console.WriteLine(); | |
ShowAllInfo(_patients); | |
Console.WriteLine("Нажмите любую клавишу для продолжения"); | |
Console.WriteLine(); | |
Console.ReadKey(); | |
bool IsWorking = true; | |
while (IsWorking) | |
{ | |
Console.WriteLine($"Для сортировки по имени нажмите {CommandSortByName}"); | |
Console.WriteLine($"Для сортировки по возрасту нажмите {CommandSortByAge}"); | |
Console.WriteLine($"Для поиска пациентов по диагнозу {CommandShowPatientsWithDiagnisis}"); | |
Console.WriteLine($"Для выхода нажмите {CommandExit}"); | |
string userInput = Console.ReadLine(); | |
switch (userInput) | |
{ | |
case CommandSortByName: | |
SortByName(); | |
break; | |
case CommandSortByAge: | |
SortByAge(); | |
break; | |
case CommandShowPatientsWithDiagnisis: | |
ShowPatientsWithDiagnisis(); | |
break; | |
case CommandExit: | |
IsWorking = false; | |
break; | |
default: | |
ShowCommandUnknown(); | |
break; | |
} | |
Console.Clear(); | |
} | |
} | |
private void SortByName() | |
{ | |
_patients = _patients.OrderBy(patient => patient.Name).ToList(); | |
ShowAllInfo(_patients); | |
Console.WriteLine("Нажмите любую клавишу для продолжения"); | |
Console.ReadKey(); | |
} | |
private void SortByAge() | |
{ | |
_patients = _patients.OrderBy(patient => patient.Age).ToList(); | |
ShowAllInfo(_patients); | |
Console.WriteLine("Нажмите любую клавишу для продолжения"); | |
Console.ReadKey(); | |
} | |
private void ShowPatientsWithDiagnisis() | |
{ | |
Console.WriteLine("Введите диагноз"); | |
string userInputDiagnosis = Console.ReadLine(); | |
var filteredPatients = _patients.Where(patient => patient.Diagnosis.ToLower() == userInputDiagnosis.ToLower()).ToList(); | |
ShowAllInfo(filteredPatients); | |
Console.WriteLine("Нажмите любую клавишу для продолжения"); | |
Console.ReadKey(); | |
} | |
private void ShowCommandUnknown() | |
{ | |
Console.WriteLine("Такой команды нет. Нажмите любую клавишу для продолжения."); | |
Console.ReadKey(); | |
} | |
private void ShowAllInfo(List<Patient> patients) | |
{ | |
foreach (var patient in patients) | |
{ | |
patient.ShowInfo(); | |
} | |
} | |
} | |
class Patient | |
{ | |
public Patient(string name, int age, string diagnosis) | |
{ | |
Name = name; | |
Diagnosis = diagnosis; | |
Age = age; | |
} | |
public string Name { get; private set; } | |
public string Diagnosis { get; private set; } | |
public int Age { get; private set; } | |
public void ShowInfo() | |
{ | |
Console.WriteLine($"Пациент: {Name}, Возраст: {Age}, Диагнос:{Diagnosis}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment