-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
287 lines (254 loc) · 12.5 KB
/
Main.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Create a new clinic object
Clinic clinic = new Clinic();
// Create two dermatologist objects
Dermatologist dermatologist1 = new Dermatologist("Dr. Fernando", "[email protected]");
Dermatologist dermatologist2 = new Dermatologist("Dr. Perera", "[email protected]");
clinic.addDermatologist(dermatologist1);
clinic.addDermatologist(dermatologist2);
boolean running = true;
try (Scanner scanner = new Scanner(System.in)) {
while (running) {
System.out.println("----------------------------------------");
System.out.println("-- Welcome to Aurora Skin Care Clinic --");
System.out.println("----------------------------------------");
System.out.println("1. Book an Appointment");
System.out.println("2. View Appointment");
System.out.println("3. Update Appointment");
System.out.println("4. Generate Invoice");
System.out.println("5. View All Dermatologists");
System.out.println("6. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1 -> bookAppointment(clinic, scanner);
case 2 -> viewAppointment(clinic, scanner);
case 3 -> updateAppointment(clinic, scanner, dermatologist1, dermatologist2);
case 4 -> generateInvoice(clinic, scanner);
case 5 -> viewAllPersons(clinic.getDermatologists()); // Polymorphic method call
case 6 -> {
running = false;
System.out.println("Exiting the system. Thank you for using Aurora Skin Care Clinic!");
}
default -> System.out.println("Invalid choice. Please try again.");
}
System.out.println();
}
}
}
// Polymorphic method to view all persons
private static void viewAllPersons(List<? extends Person> persons) {
for (Person person : persons) {
System.out.println(person.getInfo()); // Polymorphic method call
}
}
// Book an appointment
private static void bookAppointment(Clinic clinic, Scanner scanner) {
System.out.print("Enter NIC: ");
String nic = scanner.nextLine();
System.out.print("Enter Name: ");
String name = scanner.nextLine();
System.out.print("Enter Email: ");
String email = scanner.nextLine();
System.out.print("Enter Telephone: ");
String telephone = scanner.nextLine();
// New patient
Patient patient = new Patient(nic, name, email, telephone);
System.out.println("Select a Dermatologist:");
for (int i = 0; i < clinic.getDermatologists().size(); i++) {
System.out.println((i + 1) + ". " + clinic.getDermatologists().get(i).getName());
}
System.out.print("Choose a dermatologist (1 or 2): ");
int dermChoice = scanner.nextInt();
scanner.nextLine();
Dermatologist selectedDermatologist = clinic.getDermatologists().get(dermChoice - 1);
System.out.print("Enter Appointment Date (YYYY-MM-DD): ");
String date = scanner.nextLine();
System.out.println("Available slots for " + selectedDermatologist.getName() + " on " + date + ":");
for (String slot : selectedDermatologist.getAvailableSlots()) {
if (!clinic.isSlotBooked(selectedDermatologist, date, slot)) {
System.out.println(slot);
}
}
System.out.print("Enter Time (e.g., 10:00 AM): ");
String time = scanner.nextLine();
// Select treatment type
System.out.println("Available Treatments:");
System.out.println("1. Acne Treatment");
System.out.println("2. Skin Whitening");
System.out.println("3. Mole Removal");
System.out.println("4. Laser Treatment");
System.out.print("Select Treatment Type (1-4): ");
int treatmentChoice = scanner.nextInt();
scanner.nextLine();
String treatmentType;
switch (treatmentChoice) {
case 1 -> treatmentType = "Acne Treatment";
case 2 -> treatmentType = "Skin Whitening";
case 3 -> treatmentType = "Mole Removal";
case 4 -> treatmentType = "Laser Treatment";
default -> {
System.out.println("Invalid treatment choice. Defaulting to Acne Treatment.");
treatmentType = "Acne Treatment";
}
}
// Generate a new appointment ID
String appointmentId = "A" + (clinic.getAppointments().size() + 1);
Appointment appointment = new Appointment(appointmentId, date, time, selectedDermatologist, patient,
treatmentType);
clinic.addAppointment(appointment);
patient.bookAppointment(appointment);
System.out.println("Appointment booked successfully with ID: " + appointmentId);
}
// View an appointment
private static void viewAppointment(Clinic clinic, Scanner scanner) {
System.out.println("Search Appointment by:");
System.out.println("1. Date");
System.out.println("2. Patient Name");
System.out.println("3. Appointment ID");
System.out.println("4. View All Appointments");
System.out.print("Choose an option (1-4): ");
int searchOption = scanner.nextInt();
scanner.nextLine();
switch (searchOption) {
case 1 -> {
System.out.print("Enter Appointment Date (YYYY-MM-DD): ");
String searchDate = scanner.nextLine();
Appointment foundByDate = clinic.searchAppointmentByDate(searchDate);
if (foundByDate != null) {
printAppointmentDetails(foundByDate);
} else {
System.out.println("No appointment found for the given date.");
}
}
case 2 -> {
System.out.print("Enter Patient Name: ");
String searchName = scanner.nextLine();
Appointment foundByName = clinic.searchAppointmentByPatientName(searchName);
if (foundByName != null) {
printAppointmentDetails(foundByName);
} else {
System.out.println("No appointment found for the given patient name.");
}
}
case 3 -> {
System.out.print("Enter Appointment ID: ");
String searchId = scanner.nextLine();
Appointment foundById = clinic.searchAppointment(searchId);
if (foundById != null) {
printAppointmentDetails(foundById);
} else {
System.out.println("No appointment found for the given ID.");
}
}
case 4 -> {
List<Appointment> allAppointments = clinic.getAppointments();
if (allAppointments.isEmpty()) {
System.out.println("No appointments found.");
} else {
for (Appointment appointment : allAppointments) {
printAppointmentDetails(appointment);
}
}
}
default -> System.out.println("Invalid search option.");
}
}
// Update an appointment
private static void updateAppointment(Clinic clinic, Scanner scanner, Dermatologist dermatologist1,
Dermatologist dermatologist2) {
System.out.print("Enter Appointment ID to update: ");
String updateId = scanner.nextLine();
Appointment appointmentToUpdate = clinic.getAppointmentById(updateId);
if (appointmentToUpdate != null) {
System.out.println("What would you like to update?");
System.out.println("1. Date");
System.out.println("2. Time");
System.out.println("3. Dermatologist");
System.out.println("4. Treatment Type");
System.out.print("Choose an option (1-4): ");
int updateChoice = scanner.nextInt();
scanner.nextLine();
switch (updateChoice) {
case 1 -> {
System.out.print("Enter new Appointment Date (YYYY-MM-DD): ");
String newDate = scanner.nextLine();
appointmentToUpdate.setDate(newDate);
System.out.println("Appointment date updated successfully.");
}
case 2 -> {
System.out.print("Enter new Appointment Time (e.g., 10:00 AM): ");
String newTime = scanner.nextLine();
appointmentToUpdate.setTime(newTime);
System.out.println("Appointment time updated successfully.");
}
case 3 -> {
System.out.println("Select new Dermatologist:");
System.out.println("1. Dr. Fernando");
System.out.println("2. Dr. Perera");
System.out.print("Choose a dermatologist (1 or 2): ");
int newDermChoice = scanner.nextInt();
scanner.nextLine();
Dermatologist newDermatologist = newDermChoice == 1 ? dermatologist1 : dermatologist2;
appointmentToUpdate.setDermatologist(newDermatologist);
System.out.println("Dermatologist updated successfully.");
}
case 4 -> {
System.out.println("Available Treatments:");
System.out.println("1. Acne Treatment");
System.out.println("2. Skin Whitening");
System.out.println("3. Mole Removal");
System.out.println("4. Laser Treatment");
System.out.print("Select Treatment Type (1-4): ");
int newTreatmentChoice = scanner.nextInt();
scanner.nextLine();
String newTreatmentType;
switch (newTreatmentChoice) {
case 1 -> newTreatmentType = "Acne Treatment";
case 2 -> newTreatmentType = "Skin Whitening";
case 3 -> newTreatmentType = "Mole Removal";
case 4 -> newTreatmentType = "Laser Treatment";
default -> {
System.out.println("Invalid treatment choice. Defaulting to Acne Treatment.");
newTreatmentType = "Acne Treatment";
}
}
appointmentToUpdate.setTreatmentType(newTreatmentType);
System.out.println("Treatment type updated successfully.");
}
default -> System.out.println("Invalid update option.");
}
} else {
System.out.println("No appointment found with the given ID.");
}
}
// Generate an invoice
private static void generateInvoice(Clinic clinic, Scanner scanner) {
System.out.print("Enter Appointment ID to generate invoice: ");
String appointmentId = scanner.nextLine();
Appointment appointment = clinic.getAppointmentById(appointmentId);
if (appointment != null) {
double totalFee = appointment.calculateTotalFee();
double tax = totalFee * 0.025;
String invoiceId = "INV00" + (clinic.getInvoices().size() + 1);
Invoice invoice = new Invoice(invoiceId, appointment, totalFee, tax);
invoice.generateInvoiceDetails();
} else {
System.out.println("No appointment found with the given ID.");
}
}
// Print appointment details
private static void printAppointmentDetails(Appointment appointment) {
System.out.println("Appointment ID: " + appointment.getAppointmentId());
System.out.println("Patient Name: " + appointment.getPatient().getName());
System.out.println("Dermatologist: " + appointment.getDermatologist().getName());
System.out.println("Date: " + appointment.getDate());
System.out.println("Time: " + appointment.getTime());
System.out.println("Treatment Type: " + appointment.getTreatmentType());
System.out.println("--------------------------------");
}
}