Solution Review: Task VI to Task IX
Explore the practical implementation of booking appointments, displaying doctors, managing doctor availability, and patient flow in a Java healthcare project. Understand how to handle random doctor selection, update patient counts, and control appointment flow through code review and examples.
Task VI: Book an appointment
The task was to book an appointment for the patient. Look at the code below.
Look at the Patient.java file. We add a new static variable: totalPatients (at line 7). We also increment value in the constructor at line 15. Thus means that with every new patient, the total count of totalPatients will increase by .
Look at line 92 in the Hospital.java file. The bookAppointment method takes the name and age of the patient. Additionally, it takes the docType (type of the doctor) in String form. Now there are three cases:
-
If
docTypeis equal to cardiologist, we create a random number,rInt, using theMath.random()function. Here,rIntcan be any number in the range:cardiologists.size()...