-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHospitalManagementSystem.java
More file actions
58 lines (52 loc) · 1.61 KB
/
HospitalManagementSystem.java
File metadata and controls
58 lines (52 loc) · 1.61 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
class Patient {
private static String hospitalName = "City Hospital";
private static int totalPatients = 0;
private final int patientID;
private String name;
private int age;
private String ailment;
public Patient(int patientID, String name, int age, String ailment) {
this.patientID = patientID;
this.name = name;
this.age = age;
this.ailment = ailment;
totalPatients++;
}
public static int getTotalPatients() {
return totalPatients;
}
public void displayDetails() {
if (this instanceof Patient) {
System.out.println("Patient ID: " + patientID);
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Ailment: " + ailment);
System.out.println("Hospital Name: " + hospitalName);
}
}
}
public class HospitalManagementSystem {
public static void main(String[] args) {
Patient patient1 = new Patient(1, "Ajay", 30, "Fever");
Patient patient2 = new Patient(2, "Suresh", 45, "Cold");
patient1.displayDetails();
System.out.println("---------------------");
patient2.displayDetails();
System.out.println("---------------------");
System.out.println("Total Patients Admitted: " + Patient.getTotalPatients());
}
}
// SampleOutput
//Patient ID: 1
//Name: Ajay
//Age: 30
//Ailment: Fever
//Hospital Name: City Hospital
//---------------------
//Patient ID: 2
//Name: Suresh
//Age: 45
//Ailment: Cold
//Hospital Name: City Hospital
//---------------------
//Total Patients Admitted: 2