Ask Question
24 April, 15:14

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.

+4
Answers (1)
  1. 24 April, 16:07
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers