-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHospitalSystem.java
More file actions
67 lines (60 loc) · 1.89 KB
/
HospitalSystem.java
File metadata and controls
67 lines (60 loc) · 1.89 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
class Patient {
// Static Variables
private static String hospitalName = "Neelam Hospital"; // Shared across all patients
private static int totalPatients = 0; // Counter for total patients
// Instance Variables
private final int patientID; // Final variable (Unique ID for each patient)
private String name;
private int age;
private String ailment;
// Constructor
Patient(int patientID, String name, int age, String ailment) {
this.patientID = patientID;
this.name = name;
this.age = age;
this.ailment = ailment;
totalPatients++;
}
// Method to display patient details
public void displayDetails() {
if(this instanceof Patient) {
System.out.println("Hospital Name: " + hospitalName);
System.out.println("Patient ID: " + patientID);
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Ailment: " + ailment);
System.out.println();
}
}
// Method to display total number of patients
public static void getTotalPatients() {
System.out.print("Total Patients Admitted: " + totalPatients);
}
}
// Main Class
public class HospitalSystem {
public static void main(String[] args) {
// Create Objects of Patient Class
Patient patient1 = new Patient(1, "Aman", 20, "Fever");
Patient patient2 = new Patient(2, "Chirag", 25, "Headache");
// Display patient details
patient1.displayDetails();
patient2.displayDetails();
// Display total number of patients
Patient.getTotalPatients();
}
}
// Sample Output ->
//Hospital Name: Neelam Hospital
//Patient ID: 1
//Name: Aman
//Age: 20
//Ailment: Fever
//
//Hospital Name: Neelam Hospital
//Patient ID: 2
//Name: Chirag
//Age: 25
//Ailment: Headache
//
//Total Patients Admitted: 2