Ask Question
27 September, 11:00

Define a class named Doctor whose objects are records for a clinic's doctors. Derive this class from the class Person given in Lesson. A Doctor record has the doctor's name-defined in the class Person-a specialty as a string (for example Pediatrician, Obstetrician, General Practitioner, and so on), and an office-visit fee (use the type double). Give your class a reasonable complement of constructors and accessor methods. Write a driver program to test all your methods.

+5
Answers (1)
  1. 27 September, 13:31
    0
    Following is defined the required class having accessor methods and test program:

    Explanation:

    class Person

    {

    private String doc_name;

    public Person (String doc_name)

    {

    this. doc_name = doc_name;

    }

    public String getDoc_Name ()

    {

    return doc_name;

    }

    }

    class Doctor extends Person

    {

    private double office_visit_fee;

    private String Specialty;

    public Doctor (String doc_name, double office_visit_fee, String Specialty)

    {

    super (doc_name);

    this. office_visit_fee = office_visit_fee;

    this. Specialty = Specialty;

    }

    //accessor methods

    public double getOffice_Visit_Fee ()

    {

    return office_visit_fee;

    }

    public String getSpecialty ()

    {

    return Specialty;

    }

    public String toString ()

    {

    return "Doctor Name "+getDoc_Name () + " Office Visit Fee : $"+office_visit_fee+

    " Specialty : "+Specialty;

    }

    }

    class Test

    {

    public static void main (String[] args)

    {

    Doctor dctr = new Doctor ("Joseph Lister",134.56,"Obstetrician");

    System. out. println (dctr);

    }

    }

    Output:

    Doctor Name Joseph Lister Office Visit Fee : $134.56 Speciality : Obstetrician
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Define a class named Doctor whose objects are records for a clinic's doctors. Derive this class from the class Person given in Lesson. A ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers