Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Hospital
- {
- class Program
- {
- static void Main(string[] args)
- {
- Hospital hospital = new Hospital();
- hospital.Work();
- }
- }
- class Hospital
- {
- private List<Patient> _patients = new List<Patient>();
- public Hospital()
- {
- Fill();
- SortByName();
- }
- public void Work()
- {
- ConsoleKeyInfo consoleKeyInfo;
- Console.WriteLine("Press Any Button To Start");
- consoleKeyInfo = Console.ReadKey();
- while (consoleKeyInfo.Key != ConsoleKey.Escape)
- {
- Console.WriteLine("1 - Sort by Name \n2 - Sort by Age \n3 - Sort by Disease");
- switch (Console.ReadLine())
- {
- case "1":
- ShowPatients(SortByName());
- break;
- case "2":
- ShowPatients(SortByAge());
- break;
- case "3":
- ShowPatients(SortByDisease());
- break;
- default:
- Console.WriteLine("Wrong action");
- break;
- }
- Console.WriteLine("Press any button to continue");
- consoleKeyInfo = Console.ReadKey();
- Console.Clear();
- }
- }
- private List<Patient> SortByDisease()
- {
- string userInput;
- Console.Write("Inpute Disease: ");
- userInput = Console.ReadLine();
- var filteredByDisease = _patients.Where(patient => patient.Disease.ToUpper() == userInput.ToUpper());
- if(filteredByDisease.Count() == 0)
- {
- Console.WriteLine("There are no patients with such a disease");
- return null;
- }
- else
- {
- return filteredByDisease.ToList<Patient>();
- }
- }
- private List<Patient> SortByAge()
- {
- var filteredByAge = _patients.OrderBy(patient => patient.Age);
- return filteredByAge.ToList<Patient>();
- }
- private List<Patient> SortByName()
- {
- var filteredByName = _patients.OrderBy(patient => patient.FullName);
- return filteredByName.ToList<Patient>();
- }
- private void ShowPatients(List<Patient> patients)
- {
- if (patients != null)
- {
- foreach (var patient in patients)
- {
- patient.ShowInfo();
- }
- }
- }
- private void Fill()
- {
- Random random = new Random();
- _patients.Add(new Patient("John White", random.Next(1,100), TypeOfDisease.Ascariasis));
- _patients.Add(new Patient("Alister Miler", random.Next(1, 100), TypeOfDisease.Malaria));
- _patients.Add(new Patient("Nevada Ruchini", random.Next(1, 100), TypeOfDisease.Pneumonia));
- _patients.Add(new Patient("Moksi Bord", random.Next(1, 100), TypeOfDisease.Typhoid));
- _patients.Add(new Patient("Luchina Petrov", random.Next(1, 100), TypeOfDisease.Amoebiasis));
- _patients.Add(new Patient("Kobalt Seriy", random.Next(1, 100), TypeOfDisease.Pneumonia));
- _patients.Add(new Patient("Java Float", random.Next(1, 100), TypeOfDisease.Cancer));
- _patients.Add(new Patient("Waterovich Neptun", random.Next(1, 100), TypeOfDisease.Ascariasis));
- _patients.Add(new Patient("Abdul Juhamba", random.Next(1, 100), TypeOfDisease.Pneumonia));
- _patients.Add(new Patient("Hooma Sapiens", random.Next(1, 100), TypeOfDisease.Malaria));
- }
- }
- class Patient
- {
- private TypeOfDisease _disease;
- public string FullName { get; private set; }
- public int Age { get; private set; }
- public string Disease => _disease.ToString();
- public Patient(string name, int age, TypeOfDisease disease)
- {
- FullName = name;
- Age = age;
- _disease = disease;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Full Name - {FullName}, Age - {Age}, Disease - {Disease}");
- }
- }
- enum TypeOfDisease
- {
- Typhoid,
- Pneumonia,
- Malaria,
- Amoebiasis,
- Ascariasis,
- Cancer
- }
- }
Add Comment
Please, Sign In to add comment