Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Anarchy
- {
- class Program
- {
- static void Main(string[] args)
- {
- const int CommandShowSortedByFullname = 1;
- const int CommandShowSortedByAge = 2;
- const int CommandShowWithDesease = 3;
- const int CommandExit = 4;
- bool isRunning = true;
- Database database = new Database();
- Console.WriteLine($"{ CommandShowSortedByFullname} - Отсортировать всех больных по фио");
- Console.WriteLine($"{ CommandShowSortedByAge} - Отсортировать всех больных по возрасту");
- Console.WriteLine($"{ CommandShowWithDesease} - Вывести больных с определенным заболеванием");
- Console.WriteLine($"{ CommandExit} - Закрыть программу");
- while (isRunning)
- {
- Console.Write("\nВведите команду: ");
- int userInput = UserUtils.GetNumberFromUser();
- switch (userInput)
- {
- case CommandShowSortedByFullname:
- database.ShowSortedByFullname();
- break;
- case CommandShowSortedByAge:
- database.ShowSortedByAge();
- break;
- case CommandShowWithDesease:
- database.ShowWithDesease();
- break;
- case CommandExit:
- isRunning = false;
- break;
- }
- }
- }
- }
- class UserUtils
- {
- public static int GetNumberFromUser()
- {
- string userInput;
- int userNumber;
- bool isNumber = false;
- do
- {
- userInput = Console.ReadLine();
- isNumber = int.TryParse(userInput, out userNumber);
- }
- while (isNumber == false);
- return userNumber;
- }
- }
- class Patient
- {
- public Patient(string fullname, int age, string disease)
- {
- Fullname = fullname;
- Age = age;
- Desease = disease;
- }
- public string Fullname { get; private set; }
- public int Age { get; private set; }
- public string Desease { get; private set; }
- public void ShowInfo()
- {
- Console.WriteLine($"{Fullname} возраст:{Age} заболевание:{Desease}");
- }
- }
- class Database
- {
- private List<Patient> _patients = new List<Patient>();
- public Database()
- {
- _patients.Add(new Patient("Сидоров Иван Иванович", 34, "коронавирус"));
- _patients.Add(new Patient("Петров Пётр Петрович", 45, "грипп"));
- _patients.Add(new Patient("Сидоров Сидор Сидорович", 64, "мигрень"));
- _patients.Add(new Patient("Антонов Антон Антонович", 37, "грипп"));
- _patients.Add(new Patient("Джигурда Валентин Исакевич", 73, "грипп"));
- _patients.Add(new Patient("Кожедубов Артём Игоревич", 49, "анемия"));
- _patients.Add(new Patient("Натулько Алексей Петрович", 15, "коронавирус"));
- _patients.Add(new Patient("Карбонный Антон Петрович", 45, "мигрень"));
- _patients.Add(new Patient("Филь Артём Александрович", 37, "грипп"));
- _patients.Add(new Patient("Кожедубов Пётр Сидорович", 34, "коронавирус"));
- _patients.Add(new Patient("Ларетти Антон Александрович", 56, "анемия"));
- _patients.Add(new Patient("Ковальски Иван Моисеевич", 93, "анемия"));
- }
- public void ShowPatients(IEnumerable<Patient> patients)
- {
- Console.WriteLine("");
- foreach (var patient in patients)
- patient.ShowInfo();
- }
- public void ShowSortedByFullname()
- {
- Console.WriteLine("Отсортированы по ФИО:");
- var patientsSortedByFullname = _patients.OrderBy(patient => patient.Fullname);
- ShowPatients(patientsSortedByFullname);
- }
- public void ShowSortedByAge()
- {
- Console.WriteLine("Отсортированы по возрасту:");
- var patientsSortedByAge = _patients.OrderBy(patient => patient.Age);
- ShowPatients(patientsSortedByAge);
- }
- public void ShowWithDesease()
- {
- Console.WriteLine("Введите название заболевания:");
- string desease = Console.ReadLine();
- var patientsWithDesease = _patients.Where(patient => patient.Desease == desease);
- if (patientsWithDesease.Count() == 0)
- Console.WriteLine("Больных не найдено");
- else
- ShowPatients(patientsWithDesease);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement