Advertisement
OwlyOwl

HospitalAnarchy

Jun 30th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace HospitalAnarchy
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<Patient> patients = new List<Patient>
  12.             {new Patient ("Black",21,"ZPPP"),
  13.              new Patient ("Green",30,"Amnesia"),
  14.              new Patient ("Grey",32,"ZPPP"),
  15.              new Patient ("Brown",88,"Appendicitis"),
  16.              new Patient ("Yellow",13,"Allergy"),
  17.              new Patient ("Purple",24,"HIV"),
  18.              new Patient ("Pink",69,"Cholera"),
  19.              new Patient ("White",42,"Ebola"),
  20.              new Patient ("Orange",18,"Corona"),
  21.              new Patient ("Blue",27,"HIV"), };
  22.  
  23.             while (true)
  24.             {
  25.                 Console.WriteLine("1 - Sort and show by name\n2 - Sort and show by age\n3 - Search by disease");
  26.                 int command = Convert.ToInt32(Console.ReadLine());
  27.                 switch (command)
  28.                 {
  29.                     case 1:
  30.                         Console.Clear();
  31.                         var sortedByName = patients.OrderBy(patient => patient.Name);
  32.                         foreach (var patient in sortedByName)
  33.                         {
  34.                             Console.WriteLine(patient.Name);
  35.                         }
  36.                         break;
  37.                     case 2:
  38.                         Console.Clear();
  39.                         var sortedByAge = patients.OrderBy(patient => patient.Age);
  40.                         foreach (var patient in sortedByAge)
  41.                         {
  42.                             Console.WriteLine(patient.Name);
  43.                         }
  44.                         break;
  45.                     case 3:
  46.                         Console.Clear();
  47.                         Console.WriteLine("Type a disease:");
  48.                         string selectedDisease = Console.ReadLine();
  49.                         var searchResult = from Patient patient in patients
  50.                                            where patient.Disease == selectedDisease
  51.                                            select patient;
  52.                         foreach (var patient in searchResult)
  53.                         {
  54.                             Console.WriteLine(patient.Name);
  55.                         }
  56.  
  57.                         break;
  58.                 }
  59.             }
  60.         }
  61.  
  62.         class Patient
  63.         {
  64.             public string Name { get; private set; }
  65.             public int Age { get; private set; }
  66.             public string Disease { get; private set; }
  67.  
  68.             public Patient(string name, int age, string disease)
  69.             {
  70.                 Name = name;
  71.                 Age = age;
  72.                 Disease = disease;
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement