Hi I am trying to arrange the patients according to their condition that is Serious(S), Routine(R), Critical(C), and Expectant (E). I have the method but it is not implementing correctly as the program runs and builds successfully but it does not arrange them in that order any help would be much appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Client
{
class Patient: IComparable
{
private int patientnumber;
private string name;
private string timein;
private char condition;
// Default constructor:
public Patient()
{
name = "N/A";
}
// Constructor:
public Patient(string name, int patientnumber, char condition, string timein)
{
this.name = name;
this.patientnumber = patientnumber;
this.condition = condition;
this.timein = timein;
}
// Printing method:
public void PrintPatient()
{
Console.WriteLine("{0}, {1} {2} {3} ", name, patientnumber, condition, timein);
}
#region
public int CompareTo(object obj)
{
return Order(this.condition).CompareTo(Order(((Patient)obj).condition));
}
private int Order(char condition)
{
int result = 4;
switch (condition)
{
case 'S': result = 0; break;
case 'C': result = 1; break;
case 'R': result = 2; break;
case 'E': result = 3; break;
}
return result;
}
#endregion
}
class StringTest
{
static void Main()
{
// Create objects by using the new operator:
Patient patient1 = new Patient("Daniel Craig", 414092817, 'E', "12:45");
Patient patient2 = new Patient("Sally May", 654125419, 'S', "03:00");
// Create an object using the default constructor:
Patient patient3 = new Patient("Jomo Gold", 124891017, 'C', "11:20");
Patient patient4 = new Patient("Carlitos Way", 215210211, 'E', "12:20");
Patient patient5 = new Patient("Keith Baird", 215961011, 'C', "19:50");
Patient patient6= new Patient("Sony Webuye", 29154631, 'R', "12:20");
Patient patient7 = new Patient("Amy Whitehouse", 215961016, 'C', "21:00");
Patient patient8 = new Patient("Santos Abreza", 813694011, 'R', "10:20");
// Display results:
Console.Write("Patient #1: ");
patient1.PrintPatient();
Console.Write("Patient #2: ");
patient2.PrintPatient();
Console.Write("Patient #3: ");
patient3.PrintPatient();
Console.Write("Patient #4: ");
patient4.PrintPatient();
Console.Write("Patient #5: ");
patient5.PrintPatient();
Console.Write("Patient #6: ");
patient6.PrintPatient();
Console.Write("Patient #7: ");
patient7.PrintPatient();
Console.Write("Patient #8: ");
patient8.PrintPatient();
}
}
}