-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
116 lines (112 loc) · 3.19 KB
/
Program.cs
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
using project2;
List<Patient> patients = new();
void CreatePatient()
{
Console.WriteLine("Name:");
var name = Console.ReadLine();
while (string.IsNullOrEmpty(name))
{
Console.WriteLine("Name can't be null or empty!");
Console.WriteLine("Name:");
name = Console.ReadLine();
}
Console.WriteLine("Address:");
var address = Console.ReadLine();
Console.WriteLine("Age:");
var inputAge = Console.ReadLine();
while (string.IsNullOrEmpty(inputAge))
{
Console.WriteLine("Age can't be null or empty!");
Console.WriteLine("Age:");
inputAge = Console.ReadLine();
}
int age = int.Parse(inputAge);
Console.WriteLine("Injury");
var injury = Console.ReadLine();
while (string.IsNullOrEmpty(injury))
{
Console.WriteLine("Injury can't be null or empty!");
Console.WriteLine("Injury:");
injury = Console.ReadLine();
}
int id = patients.Max(p => p.Id) + 1;
var patient = new Patient(id, name, address, age, injury);
patients.Add(patient);
}
void RemovePatient()
{
Console.WriteLine("Give the patient id to remove.");
var inputId = Console.ReadLine();
while (string.IsNullOrEmpty(inputId))
{
Console.WriteLine("Id can't be null or empty!");
Console.WriteLine("Give the patient id to remove.");
inputId = Console.ReadLine();
}
int id = int.Parse(inputId);
var patient = patients.Find(p => p.Id == id);
if (patient != null)
{
patients.Remove(patient);
Console.WriteLine($"{patient.Name} is removed");
}
else
Console.WriteLine("The patient doesn't exist");
}
void UpdatePatient()
{
Console.WriteLine("give the patient id to update");
int id = int.Parse(Console.ReadLine());
Patient pa = patients.Find(p => p.Id == id);
if (pa != null)
{
Console.WriteLine("Enter new patient details:");
Console.Write("Name: ");
pa.Name = Console.ReadLine();
Console.Write("Age: ");
pa.Age = Convert.ToInt32(Console.ReadLine());
Console.Write("Address: ");
pa.Address = Console.ReadLine();
Console.WriteLine("Injury");
pa.Injury = Console.ReadLine();
}
else
Console.WriteLine("patient unavailable");
}
void Display()
{
foreach (var p in patients)
{
Console.WriteLine("ID: " + p.Id);
Console.WriteLine("Name: " + p.Name);
Console.WriteLine("Address: " + p.Address);
Console.WriteLine("Age: " + p.Age);
Console.WriteLine("Injury: " + p.Injury);
}
}
while (true)
{
Console.WriteLine("1-create a patient");
Console.WriteLine("2-remove a patient");
Console.WriteLine("3-update a patient");
Console.WriteLine("4-display the patients");
int choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
CreatePatient();
break;
case 2:
RemovePatient();
break;
case 3:
UpdatePatient();
break;
case 4:
Display();
break;
default:
Console.WriteLine("invalid,please choose another option:");
break;
}
}