Search⌘ K

Time To Code: Task I to Task V

Discover how to code a hospital management system in Java by designing classes for doctors and patients, creating constructors, adding doctors by specialty, implementing getters, and printing detailed information. This lesson guides you through hands-on tasks to build structured, real-world programming skills for the AP Computer Science exam.

📌 Note: Before starting a task, copy the code of the previous tasks.

Task I: Design the basic structure

As previously discussed, a person in a hospital can be a doctor or a patient.

Our task is to create the classes and add the instance variables to represent these two types of people. Read the following specifications carefully.

  • Every patient and doctor has a name.

  • The age of every patient and doctor is recorded.

  • A patient is given an int type code every time he/she schedules an appointment.

  • A doctor can be a cardiologist, neurosurgeon, or dietitian.

    💡 Hint: Think of a doctor as an interface and all the types of doctors as classes.

  • The status of a doctor’s availability is also recorded. A doctor may or may not be available.

  • The hospital has a name.

  • The hospital holds the ...