Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- public static void Main(string[] args)
- {
- Hospital hospital = new Hospital();
- bool isWork = true;
- while (isWork)
- isWork = hospital.Update();
- }
- }
- public class Hospital
- {
- private Random _random;
- private List<Patient> _patients;
- private string[] _diseaseNames = { "Cold", "Diarrhea", "Covid", "Tuberculosis" };
- private string[] _names = { "Mike", "Nick", "Valera", "Virgil", "Dante" };
- private string[] _choicesNames = { "Order By Age.", "Order By Name.", "Order By Name of Disease.", "Exit." };
- private int _ageMinimum = 14;
- private int _ageMaximum = 89;
- private int _amountPrisonersMinimum = 10;
- private int _amountPrisonersMaximum = 50;
- public Hospital()
- {
- _patients = new List<Patient>();
- _random = new Random();
- CreatePatients();
- }
- public bool Update()
- {
- int choice = InputChoice();
- bool isWork = true;
- switch (choice)
- {
- case 0:
- OrderByAge();
- PrintPatients(_patients);
- break;
- case 1:
- OrderByName();
- PrintPatients(_patients);
- break;
- case 2:
- string diseaseName = InputDiseaseName();
- var patientsFiltered = OrderByDiseaseName(diseaseName);
- PrintPatients(patientsFiltered);
- break;
- case 3:
- isWork = false;
- break;
- }
- return isWork;
- }
- private string InputDiseaseName()
- {
- string diseaseName = "";
- bool isInput = true;
- do
- {
- PrintDesisease();
- diseaseName = Console.ReadLine();
- isInput = !HasDiseaseName(diseaseName);
- }
- while (isInput);
- return diseaseName;
- }
- private int InputChoice()
- {
- int choice;
- bool isInput = true;
- bool isParse = false;
- do
- {
- PrintChoises();
- isParse = int.TryParse(Console.ReadLine(), out choice);
- if (isParse && choice >= 0 && choice < _choicesNames.Length)
- isInput = false;
- }
- while (isInput);
- return choice;
- }
- private bool HasDiseaseName(string disease)
- {
- bool hasDiseaseName = false;
- foreach (string diseaseName in _diseaseNames)
- {
- if (diseaseName.Equals(disease))
- {
- hasDiseaseName = true;
- break;
- }
- }
- return hasDiseaseName;
- }
- private void OrderByName()
- {
- _patients = _patients.OrderBy(patient => patient.Name).ToList();
- }
- private void OrderByAge()
- {
- _patients = _patients.OrderBy(patient => patient.Age).ToList();
- }
- private List<Patient> OrderByDiseaseName(string diseaseName)
- {
- return _patients.Where(pateint => pateint.DiseaseName.Equals(diseaseName)).ToList();
- }
- private void PrintPatients(List<Patient> patients)
- {
- Console.WriteLine();
- foreach (Patient prisoner in patients)
- Console.WriteLine(prisoner);
- }
- private void PrintDesisease()
- {
- Console.WriteLine();
- foreach (string diseaseName in _diseaseNames)
- Console.WriteLine(diseaseName);
- Console.WriteLine("Input name of disease : ");
- }
- private void PrintChoises()
- {
- Console.WriteLine();
- for (int i = 0; i < _choicesNames.Length; ++i)
- Console.WriteLine($"{i}. {_choicesNames[i]}");
- Console.WriteLine("Input your choice : ");
- }
- private void CreatePatients()
- {
- int amountCriminals = _random.Next(_amountPrisonersMinimum, _amountPrisonersMaximum);
- string name;
- string diseaseName;
- int age;
- for (int i = 0; i < amountCriminals; ++i)
- {
- name = _names[_random.Next(_names.Length)];
- diseaseName = _diseaseNames[_random.Next(_diseaseNames.Length)];
- age = _random.Next(_ageMinimum, _ageMaximum);
- _patients.Add(new Patient(name, diseaseName, age));
- }
- }
- }
- public class Patient
- {
- public string Name { get; private set; }
- public int Age { get; private set; }
- public string DiseaseName { get; private set; }
- public Patient(string name, string diseaseName, int age)
- {
- Name = name;
- DiseaseName = diseaseName;
- Age = age;
- }
- public override string ToString()
- {
- string result = "";
- result += String.Format($"{Name},{Age} - {DiseaseName}");
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment