Solution Review: Task VI to Task IX
Explore key Java programming tasks to manage a hospital system, including booking patient appointments with specific doctors, printing lists of different specialists, setting doctor availability, and controlling patient flow based on doctor status. This lesson deepens your understanding of object-oriented programming and method implementation within a healthcare context.
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()...