forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHospital_scrapper.java
182 lines (158 loc) · 5.85 KB
/
Hospital_scrapper.java
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Patient {
private int id;
private String name;
private int age;
public Patient(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
class Doctor {
private int id;
private String name;
private String specialization;
public Doctor(int id, String name, String specialization) {
this.id = id;
this.name = name;
this.specialization = specialization;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getSpecialization() {
return specialization;
}
}
class Appointment {
private int id;
private Patient patient;
private Doctor doctor;
private String date;
public Appointment(int id, Patient patient, Doctor doctor, String date) {
this.id = id;
this.patient = patient;
this.doctor = doctor;
this.date = date;
}
public int getId() {
return id;
}
public Patient getPatient() {
return patient;
}
public Doctor getDoctor() {
return doctor;
}
public String getDate() {
return date;
}
}
public class HospitalManagementSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<Patient> patients = new ArrayList<>();
List<Doctor> doctors = new ArrayList<>();
List<Appointment> appointments = new ArrayList<>();
int patientIdCounter = 1;
int doctorIdCounter = 1;
int appointmentIdCounter = 1;
while (true) {
System.out.println("Hospital Management System Menu:");
System.out.println("1. Add Patient");
System.out.println("2. Add Doctor");
System.out.println("3. Schedule Appointment");
System.out.println("4. View Appointments");
System.out.println("5. Exit");
System.out.print("Select an option (1/2/3/4/5): ");
int option = scanner.nextInt();
switch (option) {
case 1:
scanner.nextLine();
System.out.print("Enter patient name: ");
String patientName = scanner.nextLine();
System.out.print("Enter patient age: ");
int patientAge = scanner.nextInt();
patients.add(new Patient(patientIdCounter, patientName, patientAge));
patientIdCounter++;
System.out.println("Patient added successfully.");
break;
case 2:
scanner.nextLine();
System.out.print("Enter doctor name: ");
String doctorName = scanner.nextLine();
System.out.print("Enter doctor specialization: ");
String doctorSpecialization = scanner.nextLine();
doctors.add(new Doctor(doctorIdCounter, doctorName, doctorSpecialization));
doctorIdCounter++;
System.out.println("Doctor added successfully.");
break;
case 3:
System.out.print("Enter patient ID: ");
int patientId = scanner.nextInt();
System.out.print("Enter doctor ID: ");
int doctorId = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter appointment date: ");
String appointmentDate = scanner.nextLine();
Patient patient = findPatientById(patients, patientId);
Doctor doctor = findDoctorById(doctors, doctorId);
if (patient != null && doctor != null) {
appointments.add(new Appointment(appointmentIdCounter, patient, doctor, appointmentDate));
appointmentIdCounter++;
System.out.println("Appointment scheduled successfully.");
} else {
System.out.println("Patient or doctor not found.");
}
break;
case 4:
System.out.println("Appointments:");
for (Appointment appointment : appointments) {
System.out.println("Appointment ID: " + appointment.getId());
System.out.println("Patient: " + appointment.getPatient().getName());
System.out.println("Doctor: " + appointment.getDoctor().getName() + " (" + appointment.getDoctor().getSpecialization() + ")");
System.out.println("Date: " + appointment.getDate());
System.out.println();
}
break;
case 5:
System.out.println("Exiting the Hospital Management System.");
scanner.close();
System.exit(0);
default:
System.out.println("Invalid option. Please select 1, 2, 3, 4, or 5.");
}
}
}
private static Patient findPatientById(List<Patient> patients, int id) {
for (Patient patient : patients) {
if (patient.getId() == id) {
return patient;
}
}
return null;
}
private static Doctor findDoctorById(List<Doctor> doctors, int id) {
for (Doctor doctor : doctors) {
if (doctor.getId() == id) {
return doctor;
}
}
return null;
}
}