-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
168 lines (140 loc) · 5.81 KB
/
Copy pathProgram.cs
File metadata and controls
168 lines (140 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
namespace HospitalManagementSystem
{
// This is a class for patients that stores their information.
public class Patient
{
//Information in questionis the name, age and condition.
public string Name { get; set; }
public int Age { get; set; }
public string Condition { get; set; }
//This initializes the properties of each patient.
public Patient(string name, int age, string condition)
{
Name = name;
Age = age;
Condition = condition;
}
//A way to show the information of each patient.
public override string ToString()
{
return $"Name: {Name}, Age: {Age}, Condition: {Condition}";
}
}
//This is the hospital class and is used to keep track of the patients and the wards.
public class Hospital
{
//Shows the capacit, number of wards and patients being stored in a 2D array.
private const int WardCount = 3;
private const int WardCapacity = 4;
private Patient[,] Wards;
//Initializes hospital wards.
public Hospital()
{
Wards = new Patient[WardCount, WardCapacity];
}
//This is a way to add each patient to a suitable ward
public bool AddPatient(int wardNumber, Patient patient)
{
//Proves the ward number, add a number again when ward number entered is invalid
if (wardNumber < 0 || wardNumber >= WardCount)
{
Console.WriteLine($"Invalid ward number. Please select a ward between 0-{WardCount - 1}.");
return false;
}
//Helps know if there are any available beds, chooses the first available one.
for (int i = 0; i < WardCapacity; i++)
{
if (Wards[wardNumber, i] == null)
{
Wards[wardNumber, i] = patient;
Console.WriteLine($"Patient {patient.Name} added to Ward number {wardNumber} successfully.");
return true;
}
}
//Results for when there are no avaialable beds found.
Console.WriteLine($"Ward {wardNumber} is currently full.");
return false;
}
//Provides information of all patients in the occupied wards.
public void DisplayPatients()
{
Console.WriteLine("\nList of Patients:");
for (int ward = 0; ward < WardCount; ward++)
{
Console.WriteLine($"Ward {ward}:");
bool wardEmpty = true;
for (int bed = 0; bed < WardCapacity; bed++)
{
if (Wards[ward, bed] != null)
{
Console.WriteLine($" Bed {bed + 1}: {Wards[ward, bed]}");
wardEmpty = false;
}
}
if (wardEmpty)
{
Console.WriteLine(" No patients in this ward.");
}
}
}
}
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("==== Metropolitan General Hopital Management System ====");
Hospital hospital = new Hospital();
while (true)
{
//shows the different options a patient should select in the menu.
Console.WriteLine("\nMain Menu: ");
Console.WriteLine("1. Add a patient. ");
Console.WriteLine("2. Dislay Patients. ");
Console.WriteLine("3. Exit. ");
Console.Write("Enter your choice: ");
//User's input
if (int.TryParse(Console.ReadLine(), out int choice))
{
Console.WriteLine("Invalid input. Please enter a number.");
continue;
}
switch (choice)
{
//Adds the patient information.
case 1:
try
{
Console.WriteLine("Enter patient's name: ");
string name = Console.ReadLine();
Console.WriteLine("Enter patient's age: ");
int age = int.Parse(Console.ReadLine());
Console.WriteLine("Enter patient's condition: ");
string condition = Console.ReadLine();
Console.WriteLine("Enter ward number (0-2): ");
int ward = int.Parse(Console.ReadLine());
Patient newPatient = new Patient(name, age, condition);
hospital.AddPatient(ward, newPatient);
}
catch (FormatException)
{
Console.WriteLine("Invalid input. Please try again.");
}
break;
//Displays the informtion of the patient
case 2:
hospital.DisplayPatients();
break;
//The program is being exited
case 3:
Console.WriteLine("Exiting program...");
return;
//When there is an invalid selection on the menu
default:
Console.WriteLine("Invalid choice. Please select between 1-3.");
break;
}
}
}
}
}