Get hands-on practice by coding a few programming tasks.

We'll cover the following

## Task VI: Book an appointment

Consider there is an online form for booking an appointment. It takes the name and age of a patient. Then, there are three options: cardiologist, neurosurgeon, and dietitian. The patient has to select one of them and submit the form.

Our task is to book an appointment for the patient. Read the following specifications carefully.

• Write a void function, bookAppointment, in Hospital class. It takes the name, age, and a string representing the type of doctor (gathered from the online form).

• Booking an appointment means creating a patient in the hospitalâ€™s record. Remember: we gave each patient a code. Now itâ€™s the time to set a value to it. The code given to a patient will be equal to his/her turn. In other words, the first patient to attend will be given the code: $1$. The second patient to attend will be given the code: $2$. Conclusively, the nth patient will be given the code: $n$.

ðŸ’¡ Hint: Think about adding a new static instance variable in the Patient class.

• When adding a patient, maintain the record of the doctor with whom the appointment is scheduled. Generate a random number, x. Pick the xth doctor from the list and assign it to the patient.

ðŸ’¡ Note: Math.random() generates a double value. Donâ€™t forget to convert it into an int type value. If x is double, then (int)x will give its integer value.

Think about expanding the range because Math.random() gives a value greater than or equal to $0.0$ and less than $1.0$.

• By assigning, we mean printing a message in the format below.

Appointment scheduled with <Doctor-name>.


ðŸ¤” Note: Assume that the Math.random() method always chooses a doctor that is available for the appointment.

Get hands-on with 1200+ tech skills courses.